Skip to content

Instantly share code, notes, and snippets.

@yagizdemirsoy
Last active March 21, 2017 11:20
Show Gist options
  • Save yagizdemirsoy/21c0e1107bdac9f01d21ed9e336ab07c to your computer and use it in GitHub Desktop.
Save yagizdemirsoy/21c0e1107bdac9f01d21ed9e336ab07c to your computer and use it in GitHub Desktop.
Mongo Update Queries

Add new field to mongo document and set incremental values

var cursor = db.getCollection("FacetTest").find();

var i = 1;
cursor.forEach(function(x){
    db.getCollection("FacetTest").update({_id: x._id}, {$set:{Order: NumberInt(i)}}, {
     upsert: false,
     multi: false
    });
    i++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment