Created
December 23, 2014 08:15
-
-
Save piuggi/8261261db1aa531165a3 to your computer and use it in GitHub Desktop.
Update all documents in mongo a collection with an index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// where db.collection = the mongo collection you are looking to update | |
// this could be adapted in many ways | |
var collection = db.collection; var i = 0; collection.find().forEach(function(doc){ print("updating index: "+i); collection.update({_id:doc._id},{$set:{index:i}}); i++ }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment