Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "queries" and "commands" in MongoDb

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.

like image 231
Antonin Avatar asked Oct 29 '22 20:10

Antonin


1 Answers

I remembered reading it from mongodb definitive guide 2nd edition (mongo 2.6), however this book only covers mongo2.6.

  1. 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)

  2. 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
          }
       }
   }
)
like image 151
vdj4y Avatar answered Nov 15 '22 05:11

vdj4y