// To add an index to all collections in the database that start with "test" and have a field named "ts", and to run the operation in the background, use the following command: db.getCollectionNames().forEach(function(collname) { if (collname.startsWith("test")) { db.getCollection(collname).createIndex({ts: 1}, {background: true}); } });
标签:mongodb,collname,db,ts,索引,background,test From: https://www.cnblogs.com/angdh/p/17314285.html