Skip to content

Instantly share code, notes, and snippets.

@foo4u
Created August 26, 2013 23:45
Show Gist options
  • Save foo4u/6348058 to your computer and use it in GitHub Desktop.
Save foo4u/6348058 to your computer and use it in GitHub Desktop.
Editing each element in a MongoDB collection returned by find() using an integer to assign a unique value to a string field.
var foo = 0;
db.collection.find().forEach( function(doc) { doc.slug = (++foo).toString(); db.collection.save(doc); } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment