Skip to content

Commit a887e0e

Browse files
committed
Merge pull request #17 from jmikola/0.2-docs
Update docs and code examples for 0.2
2 parents 34bdc8a + f13161a commit a887e0e

File tree

7 files changed

+154
-115
lines changed

7 files changed

+154
-115
lines changed

Makefile

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.PHONY: apigen composer test docs mkdocs
22

3-
MONGODB_LIB_VERSION=`php -r 'require "src/Collection.php"; echo MongoDB\Collection::VERSION, "\n";'`
43
COMPOSER_ARGS=update --no-interaction --prefer-source
54
PHPUNIT_ARGS=--process-isolation
65

@@ -43,33 +42,30 @@ apigen:
4342
mkdocs:
4443
@command -v mkdocs >/dev/null 2>&1; \
4544
if test $$? -eq 0; then \
46-
mkdocs build --clean \
47-
else \
45+
mkdocs build --clean \
46+
else \
4847
echo "Cannot find mkdocs :("; \
4948
echo "Aborting."; \
5049
exit 1; \
51-
fi
50+
fi
5251

5352
docs-api: apigen
5453

5554
docs: mkdocs
5655

57-
58-
release: test RELEASE
56+
release/%: release-log/%
5957
@echo "Please run:"
60-
@echo " " git add RELEASE-$(MONGODB_LIB_VERSION)
61-
@echo " " git commit -m \"Add $(MONGODB_LIB_VERSION) release notes\"
62-
@echo " " git tag -a -m \"Release MongoDB library $(MONGODB_LIB_VERSION)\" $(MONGODB_LIB_VERSION)
63-
@echo " " git push --tags
64-
@echo " " make release-docs
65-
@echo "And don't forget to bump version in src/Collection.php"
58+
@echo " " git add RELEASE-$(*)
59+
@echo " " git commit -m \"Add $(*) release notes\"
60+
@echo " " git tag -a -m \"Release MongoDB library $(*)\" $(*)
61+
@echo " " git push --tags
62+
@echo " " make release-docs
6663

6764
docs:
6865
mkdocs build --clean
6966

7067
release-docs: docs
7168
mkdocs gh-deploy --clean
7269

73-
RELEASE:
74-
@git log --pretty=format:"%ad %an <%ae>%n%x09* %s%n" --date short --since="$$(git show -s --format=%ad `git rev-list --tags --max-count=1`)" > RELEASE-$(MONGODB_LIB_VERSION)
75-
70+
release-log/%:
71+
@git log --pretty=format:"%ad %an <%ae>%n%x09* %s%n" --date short --no-merges --since="$$(git show -s --format=%ad `git rev-list --tags --max-count=1`)" > RELEASE-$(*)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The preferred method of installing this library is with
3030
[Composer](https://getcomposer.org/) by running the following from your project
3131
root:
3232

33-
$ composer require "mongodb/mongodb=0.2.x-dev"
33+
$ composer require "mongodb/mongodb=^0.2.0"
3434

3535
## Generated API Docs
3636

docs/usage.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
# Usage
22

3+
## Client class
4+
5+
`MongoDB\Client` serves as an entry point for the library and driver. It is
6+
constructed with the same arguments as the driver's `MongoDB\Driver\Manager`
7+
class, which it composes. The Client class provides methods for creating a
8+
Database or Collection class (from the internal manager instance), as well as
9+
top-level operations, such as enumerating and dropping databases.
10+
311
## Collection class
412

513
`MongoDB\Collection` is perhaps the most useful class in this library. It
614
provides methods for common operations on a collection, such as inserting
715
documents, querying, updating, counting, etc.
816

9-
Constructing a `MongoDB\Collection` requires a `MongoDB\Manager` and a namespace
10-
for the collection. A [MongoDB namespace](http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace)
17+
Constructing a `MongoDB\Collection` requires a `MongoDB\Driver\Manager` and a
18+
namespace for the collection. A [MongoDB namespace](http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace)
1119
consists of a database name and collection name joined by a dot. `examples.zips`
12-
is on example of a namespace. A [write concern](http://docs.mongodb.org/manual/core/write-concern/)
20+
is one example of a namespace. Through normal use of the library, a Collection
21+
will typically be created via the `selectCollection()` method on the Manager or
22+
Database classes.
23+
24+
A [write concern](http://docs.mongodb.org/manual/core/write-concern/)
1325
and [read preference](http://docs.mongodb.org/manual/core/read-preference/) may
14-
also be provided when constructing a Collection (if omitted, the Collection will
15-
use the Manager's values as its defaults).
26+
also be provided when constructing a Collection. If these options are omitted,
27+
the Collection will inherit them from the parent through which it was selected,
28+
or the Manager.
1629

17-
## Finding a specific document
30+
### Finding a specific document
1831

1932
```
2033
<?php
@@ -51,3 +64,14 @@ array(5) {
5164
string(2) "CA"
5265
}
5366
```
67+
68+
## Database class
69+
70+
`MongoDB\Database` provides methods for common operations on a database, such
71+
as creating, enumerating, and dropping collections.
72+
73+
A [write concern](http://docs.mongodb.org/manual/core/write-concern/)
74+
and [read preference](http://docs.mongodb.org/manual/core/read-preference/) may
75+
also be provided when constructing a Database. If these options are omitted,
76+
the Database will inherit them from the Client through which it was selected,
77+
or the Manager.

examples/bootstrap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
4+
// Dependencies were installed with Composer and this is the main project
5+
$loader = require_once __DIR__ . '/../vendor/autoload.php';
6+
} elseif (file_exists(__DIR__ . '/../../../../autoload.php')) {
7+
// We're installed as a dependency in another project's `vendor` directory
8+
$loader = require_once __DIR__ . '/../../../../autoload.php';
9+
} else {
10+
throw new Exception('Can\'t find autoload.php. Did you install dependencies with Composer?');
11+
}

examples/Collection-bulkWrite.php renamed to examples/bulkwrite.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
<?php
2-
require __DIR__ . "/" . "../vendor/autoload.php";
32

4-
function dumpWriteResults(MongoDB\WriteResult $result) {
5-
printf("Inserted %d documents, upserted %d, updated %d and deleted %d\n",
6-
$result->getInsertedCount(), $result->getUpsertedCount(),
7-
$result->getModifiedCount(), $result->getDeletedCount()
3+
require_once __DIR__ . "/bootstrap.php";
4+
5+
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
6+
$collection = new MongoDB\Collection($manager, "phplib_demo.bulkwrite");
7+
8+
function dumpWriteResults(MongoDB\BulkWriteResult $result)
9+
{
10+
printf("Inserted %d documents, upserted %d, updated %d, and deleted %d\n",
11+
$result->getInsertedCount(),
12+
$result->getUpsertedCount(),
13+
$result->getModifiedCount(),
14+
$result->getDeletedCount()
815
);
916

1017
if ($result->getUpsertedCount()) {
1118
foreach ($result->getUpsertedIds() as $index => $id) {
12-
printf("upsertedId[%d]: %s", $index, $id);
19+
printf("upsertedId[%d]: %s\n", $index, $id);
1320
}
1421
}
1522
}
16-
function dumpCollection($collection) {
17-
printf("\n---\nDumping all documents in: %s.%s\n",
23+
24+
function dumpCollection($collection)
25+
{
26+
printf("Dumping all documents in: %s.%s\n",
1827
$collection->getDatabaseName(),
1928
$collection->getCollectionName()
2029
);
@@ -26,9 +35,6 @@ function dumpCollection($collection) {
2635
printf("Found %d documents\n", $n);
2736
}
2837

29-
30-
$manager = new MongoDB\Manager("mongodb://localhost:27017");
31-
$collection = new MongoDB\Collection($manager, "crud.bulkWrite");
3238
$result = $collection->bulkWrite([
3339
[
3440
"insertOne" => [
@@ -61,8 +67,9 @@ function dumpCollection($collection) {
6167
]);
6268

6369
dumpWriteResults($result);
70+
echo "\n";
6471
dumpCollection($collection);
65-
72+
echo "\n";
6673

6774
$result = $collection->bulkWrite([
6875
[
@@ -84,9 +91,10 @@ function dumpCollection($collection) {
8491
],
8592
]);
8693

87-
echo "\n\n";
8894
dumpWriteResults($result);
95+
echo "\n";
8996
dumpCollection($collection);
97+
echo "\n";
9098

9199
$result = $collection->bulkWrite([
92100
[
@@ -96,7 +104,6 @@ function dumpCollection($collection) {
96104
],
97105
]);
98106

99-
echo "\n\n";
100107
dumpWriteResults($result);
108+
echo "\n";
101109
dumpCollection($collection);
102-

examples/import-json.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)