I know I've seen this solution somewhere, but I can't seem to find it now. I'm trying to query one MongoDB database while connected to another. This should be possible without explicitly connecting to the other database before running the query. Does anyone know the correct syntax to do this?
Asked
Active
Viewed 2.2k times
25
-
What's the context here? In the shell or using a particular driver? – JohnnyHK Nov 07 '12 at 22:38
1 Answers
48
To run a command against another database on the same MongoDB server, in the mongo
shell you can use:
db.getSiblingDB('dbname').collection.command()
eg:
db.getSiblingDB('test').foo.find()

Stennie
- 63,885
- 14
- 149
- 175