geoSearchcommand provides an interface to MongoDB’s haystack index functionality. These indexes are useful for returning results based on location coordinates after collecting results based on some other query (i.e. a “haystack.”)
Field Type Description
string The collection to query.
document Query to filter documents.
array Coordinates of a point.
number Optional. Maximum distance from the specified point.
number Optional. Maximum number of documents to return.
Optional. Specifies the read concern.
The readConcern option has the following syntax:
Changed in version 3.6.
Possible read concern levels are:
"local". This is the default read concern level.
"available". This is the default for reads against secondaries when Read Operations and Causally Consistent Sessions and “level” are unspecified. The query returns the instance’s most recent data.
"majority". Available for replica sets that use WiredTiger storage engine.
"linearizable". Available for read operations on the
For more formation on the read concern levels, see Read Concern Levels.
"majority"read concern level, you can specify the
afterClusterTimeoption to have the read operation return data that meets the level requirement and the specified after cluster time requirement. For more information, see Read Operations and Causally Consistent Sessions.
For more information on the read concern levels, see Read Concern Levels.
Unless specified otherwise, the
geoSearch command limits results to 50 documents.
geoSearch is not supported for sharded clusters.
Consider the following example:
The above command returns all documents with a
restaurant having a maximum distance of 6 units from the coordinates
[ -73.9667, 40.78 ] in the collection
places up to a maximum of 30 results.
To override the default read concern level of
"local", use the
Starting in MongoDB 3.6, support for read concern
"majority"is enabled by default. For MongoDB 3.6.1 - 3.6.x, you can disable read concern
"majority". For more information, see Disable Read Concern Majority.
Regardless of the read concern level, the most recent data on a node may not reflect the most recent version of the data in the system.