I am relatively new to MongoDB and I could not find a solution for what I'm looking for.
I would like to iterate over all mongo databases and run some command for each collection of each database. I can run the following command to get all db names:
db.runCommand( { listDatabases: 1 } ).databases.forEach(function (db) { print ("db=" + db.name); });
But how do I βswitchβ a database in a forEach loop so that I can run a query on each database? I want to use something like use db.name inside the loop, but this does not work.
mongodb mongodb-query mongo-shell
Bakul G Apr 13 '15 at 15:50 2015-04-13 15:50
source share