Skip to content

Commit 6f9139e

Browse files
committed
Update documentation for PECL mongodb-0.2.0
1 parent 1285815 commit 6f9139e

File tree

6 files changed

+76
-83
lines changed

6 files changed

+76
-83
lines changed

apigen.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ skipDocPrefix:
1818
charset:
1919
- UTF-8
2020

21-
main: phongo libraries
22-
title: phongo libraries
21+
main: MongoDB PHP library
22+
title: MongoDB PHP library
2323
baseUrl: http://10gen-labs.github.io/mongo-php-libraries-prototype
2424
googleCseId: null
2525
googleAnalytics: null

docs/data.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
1-
# Example data
1+
# Example Data
22

3-
For the purpose of this documentation we will be using the
4-
[zips.json](http://media.mongodb.org/zips.json) in our examples.
3+
Usage examples in this documentation will use
4+
[zips.json](http://media.mongodb.org/zips.json). This is a dataset comprised of
5+
United States postal codes, populations, and geographic locations.
56

6-
Importing the dataset into the database can be done in several ways,
7-
for example using the following script:
7+
Importing the dataset into MongoDB can be done in several ways. The following
8+
examples uses the low-level `mongodb` PHP driver:
89

910
```php
1011
<?php
1112

1213
$file = "http://media.mongodb.org/zips.json";
13-
1414
$zips = file($file, FILE_IGNORE_NEW_LINES);
1515

16+
$bulk = new MongoDB\Driver\BulkWrite());
1617

17-
$batch = new MongoDB\WriteBatch(true);
18-
foreach($zips as $string) {
18+
foreach ($zips as $string) {
1919
$document = json_decode($string);
20-
$batch->insert($document);
20+
$bulk->insert($document);
2121
}
2222

23-
$manager = new MongoDB\Manager("mongodb://localhost");
23+
$manager = new MongoDB\Driver\Manager("mongodb://localhost");
2424

25-
$result = $manager->executeWriteBatch("examples.zips", $batch);
25+
$result = $manager->executeBulkWrite("test.zips", $bulk);
2626
printf("Inserted %d documents\n", $result->getInsertedCount());
2727

2828
?>
2929
```
3030

31-
Outputs
31+
Executing this script should yield the following output:
3232

3333
```
3434
Inserted 29353 documents
3535
```
36+
37+
You may also import the dataset using the
38+
[`mongoimport`](http://docs.mongodb.org/manual/reference/program/mongoimport/)
39+
command, which is included with MongoDB:
40+
41+
```
42+
$ mongoimport --db examples --collection zips --file zips.json
43+
```

docs/index.md

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,49 @@
1-
# Welcome to phongo libraries!
1+
# MongoDB PHP Library
22

3-
phongo libraries is a CRUD API ontop of [Phongo](https://github.com/10gen-labs/mongo-php-driver-prototype).
4-
Its purpose is to provide standard MongoDB API and follows the MongoDB CRUD API Specification[1]
5-
that all [MongoDB](http://mongodb.com) supported drivers follow.
3+
This library provides a high-level abstraction around the lower-level
4+
[PHP driver](https://github.com/10gen-labs/mongo-php-driver-prototype) (i.e. the
5+
`mongodb` extension).
66

7-
PHongo CRUD provides several convenience methods that abstract the core PHongo extension.
8-
The methods include functionality to insert a single document, counting all documents in
9-
an collection, and delete documents from a collection.
7+
While the extension provides a limited API for executing commands, queries, and
8+
write operations, this library implements an API similar to that of the
9+
[legacy PHP driver](http://php.net/manual/en/book.mongo.php). It contains
10+
abstractions for client, database, and collection objects, and provides methods
11+
for CRUD operations and common commands (e.g. index and collection management).
1012

13+
If you are developing an application with MongoDB, you should consider using
14+
this library, or another high-level abstraction, instead of the extension alone.
1115

12-
# Installation
13-
14-
As PHongo CRUD is an abstraction layer for PHongo, it naturally requires [PHongo to be
15-
installed](http://10gen-labs.github.io/mongo-php-driver-prototype/#installation):
16-
17-
$ wget https://github.com/10gen-labs/mongo-php-driver-prototype/releases/download/0.1.2/phongo-0.1.2.tgz
18-
$ pecl install phongo-0.1.2.tgz
19-
$ echo "extension=phongo.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
16+
For further information about the architecture of this library and the `mongodb`
17+
extension, see:
2018

21-
The best way to then install PHongo CRUD is via [composer](https://getcomposer.org/)
22-
by adding the following to
23-
[composer.json](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup):
19+
- http://www.mongodb.com/blog/post/call-feedback-new-php-and-hhvm-drivers
2420

25-
```json
26-
"repositories": [
27-
{
28-
"type": "vcs",
29-
"url": "https://github.com/10gen-labs/mongo-php-library-prototype"
30-
}
31-
],
32-
"require": {
33-
"ext-phongo": ">=0.1.2",
34-
"10gen-labs/mongo-php-library-prototype": "dev-master"
35-
}
36-
```
21+
# Installation
3722

38-
and then running
23+
As a high-level abstraction for the driver, this library naturally requires that
24+
the [`mongodb` extension be installed](http://10gen-labs.github.io/mongo-php-driver-prototype/#installation):
3925

40-
```shell
41-
$ composer install
42-
```
26+
$ pecl install mongodb-alpha
27+
$ echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
4328

29+
The preferred method of installing this library is with
30+
[Composer](https://getcomposer.org/) by running the following from your project
31+
root:
4432

33+
$ composer require "mongodb/mongodb=0.2.x-dev"
4534

4635
## Generated API Docs
4736

48-
If you are just interested in looking at the API provided, checkout the apidoc generated
49-
documentation on: [http://10gen-labs.github.io/mongo-php-library-prototype/api/class-MongoDB.Collection.html](http://10gen-labs.github.io/mongo-php-library-prototype/api/class-MongoDB.Collection.html)
50-
51-
37+
If you are just interested in referencing the API provided by this library, you
38+
can view generated API documentation [here](./api).
5239

5340
## MongoDB Tutorial
5441

55-
MongoDB first-timer?
56-
Checkout these links to get a quick understanding what MongoDB is, how it works, and
57-
what the most common terms used with MongoDB mean.
58-
59-
- [MongoDB CRUD Introduction](http://docs.mongodb.org/manual/core/crud-introduction/)
60-
- [What is a MongoDB Document](http://docs.mongodb.org/manual/core/document/)
61-
- [MongoDB `dot notation`](http://docs.mongodb.org/manual/core/document/#dot-notation)
62-
- [MongoDB ObjectId](http://docs.mongodb.org/manual/reference/object-id/)
63-
64-
65-
66-
[1] The specification has not been published yet - it is still a Work In Progress
42+
If you are a new MongoDB user, these links should help you become more familiar
43+
with MongoDB and introduce some of the concepts and terms you will encounter in
44+
this documentation:
6745

46+
- [Introduction to CRUD operations in MongoDB](http://docs.mongodb.org/manual/core/crud-introduction/)
47+
- [What is a MongoDB document?](http://docs.mongodb.org/manual/core/document/)
48+
- [MongoDB's *dot notation* for accessing document properties](http://docs.mongodb.org/manual/core/document/#dot-notation)
49+
- [ObjectId: MongoDB's document identifier](http://docs.mongodb.org/manual/reference/object-id/)

docs/pretty.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
$( document ).ready(function() {
3-
$('pre code').parent().addClass('prettyprint well');
1+
$(document).ready(function() {
2+
$('pre code').parent().addClass('prettyprint well');
43
prettyPrint();
54
});

docs/usage.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
# Usage
22

3+
## Collection class
34

4-
# MongoDB\Collection
5+
`MongoDB\Collection` is perhaps the most useful class in this library. It
6+
provides methods for common operations on a collection, such as inserting
7+
documents, querying, updating, counting, etc.
58

6-
MongoDB\Collection is the main object of this component.
7-
It has convenience methods for most of the _usual suspects_ tasks, such as inserting
8-
documents, querying, updating, counting, and so on.
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)
11+
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/)
13+
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).
916

10-
Constructing a MongoDB\Collection requires a MongoDB\Manager and then namespace to operate
11-
on. A [MongoDB namespace](http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace)
12-
is in the form of "databaseName.collectionName", for example: `examples.zips`.
13-
A [WriteConcern](http://docs.mongodb.org/manual/core/write-concern/) and
14-
[ReadPreference](http://docs.mongodb.org/manual/core/read-preference/) can also optionally
15-
be provided, if omitted the default values from the MongoDB\Manager will be used.
17+
## Finding a specific document
1618

17-
18-
## finding a specific document
1919
```
2020
<?php
21-
require __DIR__ . "/../". "vendor/autoload.php";
2221
23-
$manager = new MongoDB\Manager("mongodb://localhost:27017");
22+
// This path should point to Composer's autoloader
23+
require_once __DIR__ . "/vendor/autoload.php";
24+
25+
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
2426
$collection = new MongoDB\Collection($manager, "examples.zips");
2527
$sunnyvale = $collection->findOne(array("_id" => "94086"));
2628
var_dump($sunnyvale);
2729
2830
?>
2931
```
30-
Outputs
32+
33+
Executing this script should yield the following output:
34+
3135
```
3236
array(5) {
3337
["_id"]=>

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
site_name: "PHongo libraries"
1+
site_name: "MongoDB PHP library"
22
repo_url: https://github.com/10gen-labs/mongo-php-library-prototype
33
theme: spacelab
44
pages:

0 commit comments

Comments
 (0)