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)
ringa_lee
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
listDatabase
dropDatabase()
local
config
admin
It requires a little skill, but it’s not troublesome, just a script:
Probably just pass
listDatabase
得到所有的库,然后从中找到符合你条件的库,然后dropDatabase()
删除掉。注意避开关键的系统库,比如
local
,config
,admin
and wait