MongoDB Cross Database Query

I know that I saw this solution somewhere, but now I can not find it. I am trying to query one MongoDB database when connecting to another. This should be possible without explicitly connecting to another database before starting the query. Does anyone know the correct syntax for this?

+8
mongodb
source share
1 answer

To run a command with a different database on the same MongoDB server, in the mongo shell you can use:

 db.getSiblingDB('dbname').collection.command() 

eg:

 db.getSiblingDB('test').foo.find() 
+22
source share

All Articles