@@ -8,111 +8,38 @@ $uniqueDocs
88
99 .. versionadded:: 2.0
1010
11- For :term:`geospatial` queries, MongoDB may reuturn a single
11+ For :term:`geospatial` queries, MongoDB may return a single
1212 document more than once for a single query, because geospatial
1313 indexes may include multiple coordinate pairs in a single
1414 document, and therefore return the same document more than once.
1515
1616 The :operator:`$uniqueDocs` operator inverts the default behavior
17- of these queres. By default, :dbcommand:`geoNear` will always
18- return multiple instances of the same document, while the
19- :operator:`$within` operator will *never* return the same document
20- more than once. Consider the following:
21-
22- - For :dbcommand:`geoNear` queries, the default
23- :operator:`$uniqueDocs` setting is ``false``. If you specify a
24- value of ``true`` for :operator:`uniqueDocs`, MongoDB will
25- return multiple instances of a single document.
26-
27- - For :operator:`$within` queries, the default
28- :operator:`$uniqueDocs` setting is ``true``. If you specify a
29- value of ``false`` for :operator:`uniqueDocs`, MongoDB will
30- return multiple instances of a single document.
17+ of the :operator:`$within` operator. By default, the
18+ :operator:`$within` operator returns the document only once. If you
19+ specify a value of ``false`` for :operator:`uniqueDocs`, MongoDB
20+ will return multiple instances of a single document.
3121
3222 .. example::
3323
34- Given a document in the following form:
24+ Given an ``addressBook`` collection with a document in the following form:
3525
3626 .. code-block:: javascript
3727
3828 { addresses: [ { name: "Home", loc:[55.5,42.3]}, {name:"Work",loc:[32.3,44.2]}]}
3929
40- The following queries would return the same document multiple
30+ The following query would return the same document multiple
4131 times:
4232
4333 .. code-block:: javascript
4434
45- > db.runCommand( { geoNear: "geo", near: [55,44], uniqueDocs: false })
46-
47- > db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty()
35+ db.addressBook.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty()
4836
49- The following queries would return each matching document, only
37+ The following query would return each matching document, only
5038 once:
5139
5240 .. code-block:: javascript
5341
54- > db.runCommand( { geoNear: "geo", near: [55,44], uniqueDocs: true })
55-
56- > db.geo.find( {"address.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:true } }}).pretty()
57-
58- ..
59- The following example commands in the :program:`mongo` shell
60- illustrate this feature:
61-
62- .. code-block:: javascript
63-
64- > db.geoExample.insert( )
65- > db.geoExample.ensureIndex({"addresses.loc":"2d"})
66-
67- /* this will return the entry once - default for $within */
68- > db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ] } }})
69- /* this will return the entry twice */
70- > db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty()
71-
72-
73- .. Above code output:
74-
75- .. code-block:: javascript
76-
77- > db.geoExample.find( {"addresses.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:false } }}).pretty()
78- {
79- "_id" : ObjectId("504900870826ac3f09e25db6"),
80- "addresses" : [
81- {
82- "name" : "Home",
83- "loc" : [
84- 55.5,
85- 42.3
86- ]
87- },
88- {
89- "name" : "Work",
90- "loc" : [
91- 32.3,
92- 44.2
93- ]
94- }
95- ]
96- }
97- {
98- "_id" : ObjectId("504900870826ac3f09e25db6"),
99- "addresses" : [
100- {
101- "name" : "Home",
102- "loc" : [
103- 55.5,
104- 42.3
105- ]
106- },
107- {
108- "name" : "Work",
109- "loc" : [
110- 32.3,
111- 44.2
112- ]
113- }
114- ]
115- }
42+ db.addressBook.find( {"address.loc":{"$within": {"$box": [ [0,0],[100,100] ], $uniqueDocs:true } }}).pretty()
11643
11744 You cannot specify :operator:`$uniqueDocs` with :operator:`$near`
11845 or haystack queries.
0 commit comments