How to delete all MongoDB banks except admin and local

Sometimes you just need to delete all the banks and start from scratch! Using the MongoDB shell this is very easy:

const dbs = db.getMongo().getDBNames();
for(let index in dbs){
    db = db.getMongo().getDB(dbs[index] );
    const dbName = db.getName();
    if(!['admin', 'local'] .includes(dbName)) {
        print(`Deleting the database ${dbName}`);
        db.dropDatabase();
    }
}

This code securely deletes all banks keeping only the banks: Place and admin , preserving all previously created users and accesses.

As you could see scripting using the mongo shell it's very simple and powerful.

0 0 votos
Nota do Artigo
Subscribe
Notify of
guest

0 Comentários
newest
oldest most voted
Inline Feedbacks
View all comments