Do you know if it is possible to get a list of databases(like 'show dbs' in console) from javascript. I want to drop all databases from mongo via javascript file (mongo admin.js), but i can't find a way to list all databases...
Thx
I'm trying to prepare simple script but i can't find out how i can change db from script. Here is the sample javascript script. It always fails on command "use". I tried with db.eval and eval but it fails.
print(db.getMongo().getDBNames());
var environments = db.getMongo().getDBNames()
for(var environmentIndex in environments){
print(environments[environmentIndex])
eval("use staging");
//db.dropDatabase();
}
It is a simple language to learn and feels similar to programming, however it is not programming.
MongoDB uses the MongoDB Query Language (MQL), designed for easy use by developers. The documentation compares MQL and SQL syntax for common database operations.
Use db.adminCommand('listDatabases')
. For other commands see http://www.mongodb.org/display/DOCS/List+of+Database+Commands
EDIT:
In util.js
use dbname
is defined as:
shellHelper.use = function( dbname ){
db = db.getMongo().getDB( dbname );
print( "switched to db " + db.getName() );
}
http://www.mongodb.org/display/DOCS/Scripting+the+shell
db = db.getSiblingDB("otherdb") //same as use otherdb
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