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?
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()
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