- Reference >
- Operators >
- Query and Projection Operators >
- Geospatial Query Operators >
- $uniqueDocs
$uniqueDocs¶
-
$uniqueDocs¶ New in version 2.0.
The
$uniqueDocsoperator 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
$uniqueDocsonly with the$geoWithinand$nearoperators. The2dgeospatial 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
falsefor$uniqueDocs, MongoDB will return multiple instances of a single document.