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?
To run a command with a different database on the same MongoDB server, in the mongo shell you can use:
mongo
db.getSiblingDB('dbname').collection.command()
eg:
db.getSiblingDB('test').foo.find()