- Reference >
- Operators >
- Query and Projection Operators >
- Geospatial Query Operators >
- $uniqueDocs
$uniqueDocs¶
-
$uniqueDocs
¶ New in version 2.0.
The
$uniqueDocs
operator returns a document only once for a geospatial query if the document matches the query multiple times. A document might match a query multiple times if the documents contains multiple coordinate values.You can use
$uniqueDocs
only with the$geoWithin
and$near
operators. The2d
geospatial index supports$uniqueDocs
.Example
Given a collection of addresses with documents in the following form:
The following query would return the same document multiple times:
The following query would return each matching document only once:
Note
If you specify a value of
false
for$uniqueDocs
, MongoDB will return multiple instances of a single document.