Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Created January 4, 2014 22:01
Show Gist options
  • Save alejandrobernardis/8261327 to your computer and use it in GitHub Desktop.
Save alejandrobernardis/8261327 to your computer and use it in GitHub Desktop.
Create a new collection with the old indexes
var i, c,
co_name, co_new,
co_old, co_old_i,
_db = db.getSiblingDB('logs'),
_colls = ['activity.games', 'activity.session', 'activity.social', 'activity.store'];
for (i in _colls){
co_name = _colls[i];
co_old = _db[co_name];
co_old_i = co_old.getIndexes();
if(co_old.count() > 0){
co_old.renameCollection(co_name + '.old');
_db.createCollection(co_name);
co_new = _db[co_name];
for(c in co_old_i){
co_new.ensureIndex(co_old_i[c].key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment