Показ дописів із міткою NoSQL. MongoDB. Показати всі дописи
Показ дописів із міткою NoSQL. MongoDB. Показати всі дописи

пʼятницю, 18 квітня 2014 р.

Dropping all databases in MongoDB

Just used mongorestore for database transfer to another server and noticed that resulting database have more records. I may assume mongorestore does not delete existing data. Hence after googling a bit I've found a way to clear all databases first and then didn't have any problems with restore.

So here's the recipe how to drop all databases in MongoDB:
var dbs = db.getMongo().getDBNames()
for(var i in dbs){
    db = db.getMongo().getDB( dbs[i] );
    print( "dropping db " + db.getName() );
    db.dropDatabase();
}
References:
http://stackoverflow.com/questions/6376436/mongodb-drop-every-database