File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,28 @@ Behavior
51
51
Examples
52
52
--------
53
53
54
+ Matching BSON Types in Query Criteria
55
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
+
57
+ In the following example, documents in the ``restaurants`` collection use an
58
+ :manual:`ObjectId </reference/object-id/>` for their identifier (the default)
59
+ and documents in the ``zips`` collection use a string. Since ObjectID is a
60
+ special BSON type, the query criteria for selecting a restaurant must use the
61
+ :php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` class.
62
+
63
+ .. code-block:: php
64
+
65
+ $database = (new MongoDB\Client)->test;
66
+
67
+ $zip = $database->zips->findOne(['_id' => '10036']);
68
+
69
+ $restaurant = $database->restaurants->findOne([
70
+ '_id' => new MongoDB\BSON\ObjectID('594d5ef280a846852a4b3f70'),
71
+ ])
72
+
73
+ Projecting Fields
74
+ ~~~~~~~~~~~~~~~~~
75
+
54
76
The following example finds a restaurant based on the ``cuisine`` and
55
77
``borough`` fields and uses a :manual:`projection
56
78
</tutorial/project-fields-from-query-results>` to limit the fields that are
You can’t perform that action at this time.
0 commit comments