For example, I have 1,000 databases, and I want to delete all the databases that begin with a, how do I do it?
(Note that database is not collection)
It takes a little skill, but it’s not too much trouble. A script is done:
db.runCommand({listDatabases: 1}).databases.forEach(function(database) { if(database.name.match(/^a/)) { db.getDB(database.name).dropDatabase(); } });
Probably through
listDatabase
Get all the libraries, then find the libraries that meet your criteria, and thendropDatabase()
Delete it.
Pay attention to avoid key system libraries, such aslocal
,config
,admin
Wait