intro-mongo-db icon indicating copy to clipboard operation
intro-mongo-db copied to clipboard

Drop database after test.

Open iamchathu opened this issue 5 years ago • 1 comments
trafficstars

There is many databases creating from test since I use VS-Code test runner but it not getting removed after test.

iamchathu avatar Jan 03 '20 11:01 iamchathu

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();
})

sergio-cutone avatar Nov 02 '21 02:11 sergio-cutone