Commit 92617a54 authored by Jeremy Mikola's avatar Jeremy Mikola

Revise index and upgrade pages in documentation

parent 47331cba
...@@ -4,28 +4,25 @@ MongoDB PHP Library ...@@ -4,28 +4,25 @@ MongoDB PHP Library
.. default-domain:: mongodb .. default-domain:: mongodb
The |php-library| provides a high-level abstraction The |php-library| provides a high-level abstraction around the lower-level
around the lower-level `PHP Driver <https://php.net/mongodb>`_, also `PHP Driver <https://php.net/mongodb>`_, also known as the ``mongodb``
known as the ``mongodb`` extension. extension.
While the ``mongodb`` extension provides a limited API for executing While the ``mongodb`` extension provides a limited API for executing commands,
commands, queries, and write operations, the |php-library| queries, and write operations, the |php-library| implements an API similar to
implements an API similar to that of the `legacy PHP driver that of the `legacy PHP driver <http://php.net/manual/en/book.mongo.php>`_. The
<http://php.net/manual/en/book.mongo.php>`_. The library contains library contains abstractions for client, database, and collection objects, and
abstractions for client, database, and collection objects, and provides provides methods for CRUD operations and common commands such as index and
methods for CRUD operations and common commands such as index and
collection management. collection management.
If you are developing a PHP application with MongoDB, you should consider If you are developing a PHP application with MongoDB, you should consider using
using this library, or another high-level abstraction, instead of the this library, or another high-level abstraction, instead of the extension alone.
extension alone.
For additional information about the MongoDB PHP Library and the For additional information about the MongoDB PHP Library and the ``mongodb``
``mongodb`` extension, see the `Architecture Overview extension, see the `Architecture Overview
<http://php.net/manual/en/mongodb.overview.php>`_ article in the <http://php.net/manual/en/mongodb.overview.php>`_ article in the extension
extension documentation. `Derick Rethans <http://derickrethans.nl/>`_ documentation. `Derick Rethans <http://derickrethans.nl/>`_ has also written a
has also written a series of blog posts entitled *New MongoDB Drivers series of blog posts entitled *New MongoDB Drivers for PHP and HHVM*:
for PHP and HHVM*:
- `Part One: History <https://derickrethans.nl/new-drivers.html>`_ - `Part One: History <https://derickrethans.nl/new-drivers.html>`_
...@@ -42,26 +39,23 @@ If you are a new MongoDB user, these links should help you become more familiar ...@@ -42,26 +39,23 @@ If you are a new MongoDB user, these links should help you become more familiar
with MongoDB and introduce some of the concepts and terms you will encounter in with MongoDB and introduce some of the concepts and terms you will encounter in
this documentation: this documentation:
- `Introduction to CRUD operations in MongoDB - :manual:`Introduction to CRUD operations in MongoDB </core/crud>`
<http://docs.mongodb.org/manual/core/crud-introduction/>`_
- `What is a MongoDB document? - :manual:`What is a MongoDB document? </core/document>`
<http://docs.mongodb.org/manual/core/document/>`_
- `MongoDB's *dot notation* for accessing document properties - :manual:`Dot notation for accessing document properties
<http://docs.mongodb.org/manual/core/document/#dot-notation>`_ </core/document/#dot-notation>`
- `ObjectId: MongoDB's document identifier - :manual:`ObjectId: MongoDB's document identifier </reference/object-id/>`
<http://docs.mongodb.org/manual/reference/object-id/>`_
.. class:: hidden .. class:: hidden
.. toctree:: .. toctree::
:titlesonly: :titlesonly:
Installation </tutorial/install-php-library> Installation </tutorial/install-php-library>
/tutorial /tutorial
/upgrade /upgrade
/reference /reference
.. /getting-started .. /getting-started
\ No newline at end of file
...@@ -10,95 +10,94 @@ Upgrade Guide ...@@ -10,95 +10,94 @@ Upgrade Guide
:depth: 1 :depth: 1
:class: singlecol :class: singlecol
The MongoDB PHP Library and underlying :php:`mongodb Overview
extension <mongodb>` have notable API differences from --------
the legacy :php:`mongo extension <mongo>`. This page will
summarize those differences for the benefit of those The |php-library| and underlying :php:`mongodb extension <mongodb>` have notable
upgrading from the legacy driver. API differences from the legacy :php:`mongo extension <mongo>`. This page will
summarize those differences for the benefit of those upgrading from the legacy
Additionally, a community-developed driver.
`mongo-php-adapter <https://github.com/alcaeus/mongo-php-adapter>`__
library exists, which implements the `mongo Additionally, a community-developed `mongo-php-adapter
extension <http://php.net/mongo>`__ API using this library and the new <https://github.com/alcaeus/mongo-php-adapter>`_ library exists, which
driver. While this adapter library is not officially supported by implements the `mongo extension <http://php.net/mongo>`_ API using this library
and the new driver. While this adapter library is not officially supported by
MongoDB, it does bear mentioning. MongoDB, it does bear mentioning.
Collection API Collection API
~~~~~~~~~~~~~~ --------------
This library's :phpclass:`MongoDB\\Collection` class This library's :phpclass:`MongoDB\\Collection` class implements MongoDB's
implements MongoDB's cross-driver cross-driver `CRUD
`CRUD <https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst>`__ <https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst>`_
and `Index and `Index Management
Management <https://github.com/mongodb/specifications/blob/master/source/index-management.rst>`__ <https://github.com/mongodb/specifications/blob/master/source/index-management.rst>`_
specifications. Although some method names have changed in accordance specifications. Although some method names have changed in accordance with the
with the new specifications, the new class provides the same new specifications, the new class provides the same functionality as the legacy
functionality as the legacy driver's driver's :php:`MongoCollection <mongocollection>` class with some notable
`MongoCollection <http://php.net/mongocollection>`__ class with some exceptions.
notable exceptions.
Old and New Methods Old and New Methods
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
.. list-table:: .. list-table::
:header-rows: 1 :header-rows: 1
* - :php:`MongoCollection <class.mongocollection>` * - :php:`MongoCollection <mongocollection>`
- :phpclass:`MongoDB\\Collection` - :phpclass:`MongoDB\\Collection`
* - :php:`MongoCollection::aggregate() <mongocollection.aggregate>` * - :php:`MongoCollection::aggregate() <mongocollection.aggregate>`
- :phpmethod:`MongoDB\\Collection::aggregate` - :phpmethod:`MongoDB\\Collection::aggregate()`
* - :php:`MongoCollection::aggregateCursor() <mongocollection.aggregatecursor>` * - :php:`MongoCollection::aggregateCursor() <mongocollection.aggregatecursor>`
- :phpmethod:`MongoDB\\Collection::aggregate` - :phpmethod:`MongoDB\\Collection::aggregate()`
* - :php:`MongoCollection::batchInsert() <mongocollection.batchinsert>` * - :php:`MongoCollection::batchInsert() <mongocollection.batchinsert>`
- :phpmethod:`MongoDB\\Collection::insertMany` - :phpmethod:`MongoDB\\Collection::insertMany()`
* - :php:`MongoCollection::count() <mongocollection.count>` * - :php:`MongoCollection::count() <mongocollection.count>`
- :phpmethod:`MongoDB\\Collection::count` - :phpmethod:`MongoDB\\Collection::count()`
* - :php:`MongoCollection::createDBRef() <mongocollection.createdbref>` * - :php:`MongoCollection::createDBRef() <mongocollection.createdbref>`
- Not yet implemented. See :issue:`PHPLIB-24` - Not yet implemented. See :issue:`PHPLIB-24`.
* - :php:`MongoCollection::createIndex() <mongocollection.createindex>` * - :php:`MongoCollection::createIndex() <mongocollection.createindex>`
- :phpmethod:`MongoDB\\Collection::createIndex` - :phpmethod:`MongoDB\\Collection::createIndex()`
* - :php:`MongoCollection::deleteIndex() <mongocollection.deleteindex>` * - :php:`MongoCollection::deleteIndex() <mongocollection.deleteindex>`
- :phpmethod:`MongoDB\\Collection::dropIndex` - :phpmethod:`MongoDB\\Collection::dropIndex()`
* - :php:`MongoCollection::deleteIndexes() <mongocollection.deleteindexes>` * - :php:`MongoCollection::deleteIndexes() <mongocollection.deleteindexes>`
- :phpmethod:`MongoDB\\Collection::dropIndexes` - :phpmethod:`MongoDB\\Collection::dropIndexes()`
* - :php:`MongoCollection::drop() <mongocollection.drop>` * - :php:`MongoCollection::drop() <mongocollection.drop>`
- :phpmethod:`MongoDB\\Collection::drop` - :phpmethod:`MongoDB\\Collection::drop()`
* - :php:`MongoCollection::distinct() <mongocollection.distinct>` * - :php:`MongoCollection::distinct() <mongocollection.distinct>`
- :phpmethod:`MongoDB\\Collection::distinct` - :phpmethod:`MongoDB\\Collection::distinct()`
* - :php:`MongoCollection::ensureIndex() <mongocollection.ensureindex>` * - :php:`MongoCollection::ensureIndex() <mongocollection.ensureindex>`
- :phpmethod:`MongoDB\\Collection::createIndex` - :phpmethod:`MongoDB\\Collection::createIndex()`
* - :php:`MongoCollection::find() <mongocollection.find>` * - :php:`MongoCollection::find() <mongocollection.find>`
- :phpmethod:`MongoDB\\Collection::find` - :phpmethod:`MongoDB\\Collection::find()`
* - :php:`MongoCollection::findAndModify() <mongocollection.findandmodify>` * - :php:`MongoCollection::findAndModify() <mongocollection.findandmodify>`
- :phpmethod:`MongoDB\\Collection::findOneAndDelete()`,
- :phpmethod:`MongoDB\\Collection::findOneAndDelete`, :phpmethod:`MongoDB\\Collection::findOneAndReplace()`, and
:phpmethod:`MongoDB\\Collection::findOneAndReplace`, and
:phpmethod:`MongoDB\\Collection::findOneAndUpdate()` :phpmethod:`MongoDB\\Collection::findOneAndUpdate()`
* - :php:`MongoCollection::findOne() <mongocollection.findone>` * - :php:`MongoCollection::findOne() <mongocollection.findone>`
- :phpmethod:`MongoDB\\Collection::findOne` - :phpmethod:`MongoDB\\Collection::findOne()`
* - :php:`MongoCollection::getDBRef() <mongocollection.getdbref>` * - :php:`MongoCollection::getDBRef() <mongocollection.getdbref>`
- Not implemented. See :issue:`PHPLIB-24` - Not implemented. See :issue:`PHPLIB-24`.
* - :php:`MongoCollection::getIndexInfo() <mongocollection.getindexinfo>` * - :php:`MongoCollection::getIndexInfo() <mongocollection.getindexinfo>`
- :phpmethod:`MongoDB\\Collection::listIndexes` - :phpmethod:`MongoDB\\Collection::listIndexes()`
* - :php:`MongoCollection::getName() <mongocollection.getname>` * - :php:`MongoCollection::getName() <mongocollection.getname>`
- :phpmethod:`MongoDB\\Collection::getCollectionName` - :phpmethod:`MongoDB\\Collection::getCollectionName()`
* - :php:`MongoCollection::getReadPreference() <mongocollection.getreadpreference>` * - :php:`MongoCollection::getReadPreference() <mongocollection.getreadpreference>`
- Not implemented. - Not implemented.
...@@ -111,21 +110,21 @@ Old and New Methods ...@@ -111,21 +110,21 @@ Old and New Methods
* - :php:`MongoCollection::group() <mongocollection.group>` * - :php:`MongoCollection::group() <mongocollection.group>`
- Not yet implemented. See :issue:`PHPLIB-177`. - Not yet implemented. See :issue:`PHPLIB-177`.
Use :phpmethod:`MongoDB\\Database::command`. Use :phpmethod:`MongoDB\\Database::command()`.
* - :php:`MongoCollection::insert() <mongocollection.insert>` * - :php:`MongoCollection::insert() <mongocollection.insert>`
- :phpmethod:`MongoDB\\Collection::insertOne` - :phpmethod:`MongoDB\\Collection::insertOne()`
* - :php:`MongoCollection::parallelCollectionScan() <mongocollection.parallelcollectionscan>` * - :php:`MongoCollection::parallelCollectionScan() <mongocollection.parallelcollectionscan>`
- Not implemented. - Not implemented.
* - :php:`MongoCollection::remove() <mongocollection.remove>` * - :php:`MongoCollection::remove() <mongocollection.remove>`
- :phpmethod:`MongoDB\\Collection::deleteMany` and - :phpmethod:`MongoDB\\Collection::deleteMany()` and
:phpmethod:`MongoDB\\Collection::deleteOne` :phpmethod:`MongoDB\\Collection::deleteOne()`
* - :php:`MongoCollection::save() <mongocollection.save>` * - :php:`MongoCollection::save() <mongocollection.save>`
- :phpmethod:`MongoDB\\Collection::insertOne` or - :phpmethod:`MongoDB\\Collection::insertOne()` or
:phpmethod:`MongoDB\\Collection::replaceOne` with the ``upsert`` :phpmethod:`MongoDB\\Collection::replaceOne()` with the ``upsert``
option. option.
* - :php:`MongoCollection::setReadPreference() <mongocollection.setreadpreference>` * - :php:`MongoCollection::setReadPreference() <mongocollection.setreadpreference>`
...@@ -135,33 +134,32 @@ Old and New Methods ...@@ -135,33 +134,32 @@ Old and New Methods
- Not implemented. - Not implemented.
* - :php:`MongoCollection::setWriteConcern() <mongocollection.setwriteconcern>` * - :php:`MongoCollection::setWriteConcern() <mongocollection.setwriteconcern>`
- Not implemented. Use :phpmethod:`MongoDB\\Collection::withOptions` - Not implemented. Use :phpmethod:`MongoDB\\Collection::withOptions()`
* - :php:`MongoCollection::update() <mongocollection.update>` * - :php:`MongoCollection::update() <mongocollection.update>`
- :phpmethod:`MongoDB\\Collection::replaceOne`, - :phpmethod:`MongoDB\\Collection::replaceOne()`,
:phpmethod:`MongoDB\\Collection::updateMany`, and :phpmethod:`MongoDB\\Collection::updateMany()`, and
:phpmethod:`MongoDB\\Collection::updateOne`. :phpmethod:`MongoDB\\Collection::updateOne()`.
* - :php:`MongoCollection::validate() <mongocollection.validate>` * - :php:`MongoCollection::validate() <mongocollection.validate>`
- Not implemented. - Not implemented.
A guiding principle in designing the new APIs was that explicit method A guiding principle in designing the new APIs was that explicit method names are
names are preferable to overloaded terms found in the old API. For preferable to overloaded terms found in the old API. For instance,
instance, :php:`MongoCollection::save() <mongocollection.save>` and :php:`MongoCollection::save() <mongocollection.save>` and
:php:`MongoCollection::findAndModify() <mongocollection.findandmodify>` :php:`MongoCollection::findAndModify() <mongocollection.findandmodify>`
have different modes of operation, depending on their arguments. have different modes of operation, depending on their arguments. Methods were
Methods were also split to distinguish between :manual:`updating also split to distinguish between :manual:`updating specific fields
specific fields </tutorial/modify-documents>` and :manual:`full-document </tutorial/modify-documents>` and :manual:`full-document replacement
replacement </tutorial/modify-documents/#replace-the-document>`. </tutorial/modify-documents/#replace-the-document>`.
Group Command Helper Group Command Helper
~~~~~~~~~~~~~~~~~~~~ --------------------
:phpclass:`MongoDB\\Collection` does not :phpclass:`MongoDB\\Collection` does not yet have a helper method for the
yet have a helper method for the :manual:`group :manual:`group </reference/command/group>` command; however, it is planned in
</reference/command/group>` command; however, it is planned in :issue:`PHPLIB-177`. The following example demonstrates how to execute a group
:issue:`PHPLIB-177`. The following example demonstrates how to execute command using the :phpmethod:`MongoDB\\Database::command()` method:
a group command using the :phpmethod:`MongoDB\\Database::command()` method:
.. code-block:: php .. code-block:: php
...@@ -180,13 +178,12 @@ a group command using the :phpmethod:`MongoDB\\Database::command()` method: ...@@ -180,13 +178,12 @@ a group command using the :phpmethod:`MongoDB\\Database::command()` method:
$resultDocument = $cursor->toArray()[0]; $resultDocument = $cursor->toArray()[0];
MapReduce Command Helper MapReduce Command Helper
~~~~~~~~~~~~~~~~~~~~~~~~ ------------------------
:phpclass:`MongoDB\\Collection` does not yet have a helper method for :phpclass:`MongoDB\\Collection` does not yet have a helper method for the
the :manual:`mapReduce </reference/command/mapReduce/>` command; :manual:`mapReduce </reference/command/mapReduce>` command; however, that is
however, that is planned in :issue:`PHPLIB-53`. The following example planned in :issue:`PHPLIB-53`. The following example demonstrates how to execute
demonstrates how to execute a mapReduce command using the a mapReduce command using the :phpmethod:`MongoDB\\Database::command()` method:
:phpmethod:`MongoDB\\Database::command()` method:
.. code-block:: php .. code-block:: php
...@@ -201,58 +198,50 @@ demonstrates how to execute a mapReduce command using the ...@@ -201,58 +198,50 @@ demonstrates how to execute a mapReduce command using the
]); ]);
$resultDocument = $cursor->toArray()[0]; $resultDocument = $cursor->toArray()[0];
?>
DBRef Helpers DBRef Helpers
~~~~~~~~~~~~~ -------------
:phpclass:`MongoDB\\Collection` does not yet :phpclass:`MongoDB\\Collection` does not yet have helper methods for working
have helper methods for working with with :manual:`DBRef </reference/database-references>` objects; however, that is
:manual:`DBRef </reference/database-references>` planned in :issue:`PHPLIB-24`.
objects; however, that is planned in
:issue:`PHPLIB-24`.
MongoCollection::save() Removed MongoCollection::save() Removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -------------------------------
:php:`MongoCollection::save() <mongocollection.save>`, :php:`MongoCollection::save() <mongocollection.save>`, which was syntactic sugar
which was syntactic sugar for an insert or upsert operation, has been for an insert or upsert operation, has been removed in favor of explicitly using
removed in favor of explicitly using
:phpmethod:`MongoDB\\Collection::insertOne` or :phpmethod:`MongoDB\\Collection::insertOne` or
:phpmethod:`MongoDB\\Collection::replaceOne` with the ``upsert`` :phpmethod:`MongoDB\\Collection::replaceOne` (with the ``upsert`` option).
option).
.. .. figure:: img/save-flowchart.png .. .. figure:: /images/save-flowchart.png
.. :alt: save() flowchart .. :alt: save() flowchart
While the ``save`` While the ``save`` method does have its uses for interactive environments, such
method does have its uses for interactive environments, such as the as the mongo shell, it was intentionally excluded from the `CRUD specification
mongo shell, it was intentionally excluded from the <https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst>`_
`CRUD <https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst>`_ for language drivers. Generally, application code should know if the document
specification for language drivers. Generally, application code should has an identifier and be able to explicitly insert or replace the document and
know if the document has an identifier and be able to explicitly insert handle the returned :phpclass:`MongoDB\\InsertOneResult` or
or replace the document and handle the returned InsertResult or :phpclass:`MongoDB\\UpdateResult`, respectively. This also helps avoid
UpdateResult, respectively. This also helps avoid inadvertent and inadvertent and potentially dangerous :manual:`full-document replacements
potentially dangerous :manual:`full-document </tutorial/modify-documents>`.
replacements </tutorial/modify-documents>`.
Accessing IDs of Inserted Documents Accessing IDs of Inserted Documents
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the legacy driver, :php:`MongoCollection::insert() In the legacy driver, :php:`MongoCollection::insert() <mongocollection.insert>`,
<mongocollection.insert>`, :php:`MongoCollection::batchInsert() :php:`MongoCollection::batchInsert() <mongocollection.batchinsert`, and
<mongocollection.batchinsert`, and :php:`MongoCollection::save() :php:`MongoCollection::save() <mongocollection.save>` (when inserting) would
<mongocollection.save>` (when inserting) would modify their input modify their input argument by injecting an ``_id`` key with a generated
argument by injecting an ``_id`` key containing the generated ObjectId ObjectId (i.e. :php:`MongoId <class.mongoid>` object). This behavior was a bit
(i.e. :php:`MongoId <class.mongoid>` object). This behavior was a bit of a hack, as it did not rely on the argument being :php:`passed by reference
of a hack, as it did not rely on the argument being :php:`passed by <language.references.pass>`; instead, it directly modified memory through the
reference <language.references.pass>`; instead, it directly modified extension API and could not be implemented in PHP userland. As such, it is no
memory through the extension API and could not be implemented in PHP longer done in the new driver and library.
userland. As such, it is no longer done in the new driver and library.
IDs of inserted documents (whether generated or not) may be accessed IDs of inserted documents (whether generated or not) may be accessed through the
through the result objects returned by the write methods: following methods on the write result objects:
- :phpmethod:`MongoDB\\InsertOneResult::getInsertedId()` for - :phpmethod:`MongoDB\\InsertOneResult::getInsertedId()` for
:phpmethod:`MongoDB\\Collection::insertOne()` :phpmethod:`MongoDB\\Collection::insertOne()`
...@@ -261,13 +250,11 @@ through the result objects returned by the write methods: ...@@ -261,13 +250,11 @@ through the result objects returned by the write methods:
- :phpmethod:`MongoDB\\BulkWriteResult::getInsertedIds()` for - :phpmethod:`MongoDB\\BulkWriteResult::getInsertedIds()` for
:phpmethod:`MongoDB\\Collection::bulkWrite()` :phpmethod:`MongoDB\\Collection::bulkWrite()`
``MongoWriteBatch`` Bulk Write Operations
~~~~~~~~~~~~~~~~~~~ ---------------------
The legacy driver's The legacy driver's :php:`MongoWriteBatch <class.mongowritebatch>` classes have
:php:`MongoWriteBatch <class.mongowritebatch>` been replaced with a general-purpose
classes have been replaced with a general-purpose :phpmethod:`MongoDB\\Collection::bulkWrite()` method. Whereas the legacy driver
:phpmethod:`MongoDB\\Collection::bulkWrite` method. Whereas the only allowed bulk operations of the same type, the new method allows operations
legacy driver only allowed bulk operations of the same type, the new to be mixed (e.g. inserts, updates, and deletes).
method allows operations to be mixed (e.g. inserts, updates, and
deletes).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment