Skip to content

Instantly share code, notes, and snippets.

@munkhorgil
Created October 11, 2019 07:03
Show Gist options
  • Save munkhorgil/40d48318190bd3daeba12c19ad659485 to your computer and use it in GitHub Desktop.
Save munkhorgil/40d48318190bd3daeba12c19ad659485 to your computer and use it in GitHub Desktop.
Remove all mongo dbs except local, admin
// Remove all databases, except local, admin
// on command line: mongo filename.js
const dbs = db.getMongo().getDBNames()
for(var i in dbs){
db = db.getMongo().getDB( dbs[i] );
if (db.getName() !== 'admin' && db.getName() !== 'local')
{
print( "dropping db " + db.getName() );
db.dropDatabase();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment