Navigation
This version of the documentation is archived and no longer supported.

$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. The 2d geospatial index supports $uniqueDocs.

Example

Given a collection of addresses with documents in the following form:

{ addrs : [ { name : "H" , loc : [ 55.5 , 42.3 ] } , { name : "W" , loc : [ 32.3 , 44.2 ] } ] }

The following query would return the same document multiple times:

db.list.find( { "addrs.loc" : { $geoWithin : { $box : [ [ 0 , 0 ] , [ 100 , 100 ] ] } } } )

The following query would return each matching document only once:

db.list.find( { "addrs.loc" : { $geoWithin : { $box : [ [ 0 , 0 ] , [ 100 , 100 ] ], $uniqueDocs: true } } } )

Note

If you specify a value of false for $uniqueDocs, MongoDB will return multiple instances of a single document.