Commit 0be53f92 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-208: Remind users about BSON comparison behavior

parent 153ed364
ref: note-bson-comparison
content: |
When evaluating query criteria, MongoDB compares types and values according to
its own :manual:`comparison rules for BSON types
</reference/bson-type-comparison-order>`, which differs from PHP's
:php:`comparison <manual/en/types.comparisons.php>` and :php:`type juggling
<manual/en/language.types.type-juggling.php>` rules. When matching a special
BSON type the query criteria should use the respective :php:`BSON class
<manual/en/book.bson.php>` in the driver (e.g. use
:php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` to match an
:manual:`ObjectId </reference/object-id/>`).
...
......@@ -42,6 +42,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
.. todo: add output and examples
See Also
......
......@@ -42,6 +42,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Example
-------
......
......@@ -44,6 +44,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Example
-------
......
......@@ -42,6 +42,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -41,6 +41,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -43,6 +43,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -43,6 +43,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -45,6 +45,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -45,6 +45,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -44,6 +44,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Example
-------
......
......@@ -42,6 +42,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -44,6 +44,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Examples
--------
......
......@@ -41,6 +41,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
.. todo: add examples
See Also
......
......@@ -44,6 +44,11 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
.. todo: add examples
See Also
......
......@@ -92,6 +92,8 @@ The |php-library| provides the :phpmethod:`MongoDB\\Collection::findOne()` and
:phpmethod:`MongoDB\\Collection::aggregate()` method for performing
:manual:`aggregation operations </core/aggregation-pipeline>`.
.. include:: /includes/extracts/note-bson-comparison.rst
Find One Document
~~~~~~~~~~~~~~~~~
......@@ -137,6 +139,16 @@ The output would then resemble::
}
}
.. note::
The criteria in this example matched an ``_id`` with a string value of
``"94301"``. The same criteria would not have matched a document with an
integer value of ``94301`` due to MongoDB's :manual:`comparison rules for
BSON types </reference/bson-type-comparison-order>`. Similarly, users should
use a :php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` object
when matching an ``_id`` with an :manual:`ObjectId </reference/object-id/>`
value, as strings and ObjectIds are not directly comparable.
.. seealso:: :phpmethod:`MongoDB\\Collection::findOne()`
Find Many Documents
......
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