To delete all databases from our MongoDB instances, run the following command:
db.adminCommand("listDatabases").databases.forEach(function(d)
{
if(d.name!="admin" && d.name!="local" && d.name!="config")
{
db.getSiblingDB(d.name).dropDatabase();
}
}
);