Manually index mongodb

If you copy a fw8 database you may lose the indexes on the collections which will affect performance. To remedy this you can run a script to reindex the collections. Below is the script required. You can run this in the command line or use an ide type program like MongoChef or RoboMongo.



var background = { background: true };
var backgroundSparse = { background: true, sparse: true };
function createAssetIndexes() {
  db.Assets.ensureIndex({ P: 1, Br: 1 }, background);
  db.Assets.ensureIndex({ PP: 1, Br: 1 }, background);
  db.Assets.ensureIndex({ T: 1 }, background);
  db.Assets.ensureIndex({ ST: 1 }, background);
  db.Assets.ensureIndex({ T: 1, ST: 1 }, background);
  db.Assets.ensureIndex({ U: 1, Br: 1 }, backgroundSparse);
  db.Assets.ensureIndex({ AAcc: 1 }, background);
  db.Assets.ensureIndex({ TA: 1 }, background);
  db.Assets.ensureIndex({ CD: -1 }, background);
}
function createAssetsArchiveIndexes() {
  db.AssetsArchive.ensureIndex({ P: 1 }, background);
}
function createUserSessionIndexes() {
  db.UserSessions.ensureIndex({ P: 1 }, background);
  db.UserSessions.ensureIndex({ U: 1 }, background);
}
function createUserAccountIndexes() {
  db.UserAccounts.ensureIndex({ Un: 1 }, background);
}
print("Creating asset indexes...");
createAssetIndexes();
print("Creating assets archive indexes...");
createAssetsArchiveIndexes();
print("Creating user session indexes...");
createUserSessionIndexes();
print("Creating user  indexes...");
createUserAccountIndexes();
print("Creating GridFS  indexes...");