For example, I have 1,000 databases and want to delete all databases starting with a. How do I do this?
(note database not collection)
过去多啦不再A梦2017-05-02 09:27:50
It requires a little skill, but it’s not troublesome, just a script:
db.runCommand({listDatabases: 1}).databases.forEach(function(database) {
if(database.name.match(/^a/)) {
db.getDB(database.name).dropDatabase();
}
});
Probably just pass listDatabase
得到所有的库,然后从中找到符合你条件的库,然后dropDatabase()
删除掉。
注意避开关键的系统库,比如local
, config
, admin
and wait