References to reindexing MongoDB collections are usually per collection:
db.mycollection.reIndex();
I'd like to reindex a number of collections all at once. One-by-one can get a bit tiring.
What's the appropriate command to issue reIndex();
across all collections?
Slightly smaller version of Sergio's answer:
db.getCollectionNames().forEach(function(collection){db[collection].reIndex()});
There is no need to get a reference to the collection first.
What about this? It's still one-by-one for the database, but just one command for you.
db.getCollectionNames().forEach(function(coll_name) {
var coll = db.getCollection(coll_name);
coll.reIndex();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.