intro-mongo-db
intro-mongo-db copied to clipboard
Drop database after test.
trafficstars
There is many databases creating from test since I use VS-Code test runner but it not getting removed after test.
I found that this works for me.
Run this command in Mongo and add the database names that you DO NOT wish to remove as it will remove everything else.
DO NOT delete "local", "admin" and "config".
db.adminCommand("listDatabases").databases.forEach( function (d) {
if (d.name != "local" && d.name != "admin" && d.name != "config" && d.name != "whatever")
db.getSiblingDB(d.name).dropDatabase();
})