Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB cross database query

Tags:

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?

like image 778
jbl429 Avatar asked Nov 07 '12 21:11

jbl429


1 Answers

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() 
like image 52
Stennie Avatar answered Oct 22 '22 10:10

Stennie