Database Reference
In-Depth Information
"loc" : { "lon" : -73.9785, "lat" : 40.7514 },
"state" : "New York", "zip" : 10178 }
{ "_id" : ObjectId("4d291187888cec7267e55d8a"), "city" : "New York City",
"loc" : { "lon" : -73.9791, "lat" : 40.7524 },
"state" : "New York", "zip" : 10165 }
Specifying a reasonable limit will ensure the fastest query response times. If no limit is
given, then the limit will automatically be set to 100 to keep the query from returning
the entire data set. If you require more than 100 results, specify the number as a limit:
> db.zips.find({'loc': {$near: [ -73.977842, 40.752315 ]}}).limit(500)
E.2
Advanced queries
Although $near queries are good for a lot of use cases, a few more advanced query
techniques are also available. Instead of querying, you can run a special command
called geoNear that returns the distances for each nearby object and several stats
about the query itself:
> db.runCommand({'geoNear': 'zips', near: [-73.977842, 40.752315], num: 2})
{
"ns" : "geo.zips",
"near" : "0110000111011010011111010110010011001111111011011100",
"results" : [
{
"dis" : 0.001121663764459287,
"obj" : {
"_id" : ObjectId("4d291187888cec7267e55d8d"),
"city" : "New York City",
"loc" : {
"lon" : -73.9768,
"lat" : 40.7519
},
"state" : "New York",
"zip" : 10168
}
},
{
"dis" : 0.001126847051610947,
"obj" : {
"_id" : ObjectId("4d291187888cec7267e55d97"),
"city" : "New York City",
"loc" : {
"lon" : -73.9785,
"lat" : 40.7514
},
"state" : "New York",
"zip" : 10178
}
}
],
"stats" : {
"time" : 0,
"btreelocs" : 4,
Search WWH ::




Custom Search