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?
MongoDB cross database query
Asked Answered
What's the context here? In the shell or using a particular driver? –
Seel
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()
© 2022 - 2024 — McMap. All rights reserved.