Hello MongoDB documentation specifies that there are several ways to retrieve documents near a geographical position :
using "queries" (in find queries for instance) : https://docs.mongodb.com/v3.0/reference/operator/query-geospatial/
or using "commands" : https://docs.mongodb.com/manual/reference/command/nav-geospatial/
I don't understand the difference between commands and operator/queries ? These commands seem to do exactly the same thing as their query counterparts ?
PS : I use scala reactivemongo connector in my application.
I remembered reading it from mongodb definitive guide 2nd edition (mongo 2.6), however this book only covers mongo2.6.
query command cover several tasks like CRUD, drop database. While database Command cover everything else, including administrative tasks, cloning database, etc. (this book uses mongodb v2.6, I am sure in mongodbV3.2 queryCommand has more functions that can cover some adminitrative tasks)
query in mongoshell returned a cursor, while database command returned an document that always has "ok" status, and one or more information.
example querying geolocation with database Command
db.runCommand( {
geoNear: <collection> ,
near: { type: "Point" , coordinates: [ <coordinates> ] } ,
spherical: true,
...
} )
example of querying database with query command
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: 1000,
$maxDistance: 5000
}
}
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With