84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
比方说我有1000个database,想要删除其中所有以a开头的数据库,请问怎么操作?(注意是database不是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