Skip to content

Instantly share code, notes, and snippets.

@mediocretes
Created January 20, 2011 16:31
Show Gist options
  • Save mediocretes/788131 to your computer and use it in GitHub Desktop.
Save mediocretes/788131 to your computer and use it in GitHub Desktop.
migrate_one_faster = function(c) {
print("Collection: " + c);
print("Initial Count: " + db[c].count());
i = 0;
db[c].find({created_at:{$exists:true}}).forEach(function(item){
if(i++ % 10000 == 0){ print("progress: " + i);}
item.timestamp = item.created_at;
delete item.created_at;
db[c].save(item);
print(tojson(db.getLastErrorObj()));
});
}
//prints this:
{
"theshard" : "set1/mongo-1a.public.aws.igodigital.net:27017,mongo-1b.public.aws.igodigital.net:27017,mongo-1d.public.aws.igodigital.net:27017",
"err" : null,
"n" : 0,
"lastOp" : NumberLong(0),
"ok" : 1,
"singleShard" : "set1/mongo-1a.public.aws.igodigital.net:27017,mongo-1b.public.aws.igodigital.net:27017,mongo-1d.public.aws.igodigital.net:27017"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment