Skip to content

Instantly share code, notes, and snippets.

@sturadnidge
Created May 8, 2013 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturadnidge/5541742 to your computer and use it in GitHub Desktop.
Save sturadnidge/5541742 to your computer and use it in GitHub Desktop.
MongoDB shell tricks: add a 'created' field to documents long after the fact
db.test.find({}).forEach( function(obj) {
var _idTimestamp = obj._id.getTimestamp();
obj.created = _idTimestamp.getTime();
db.test.save(obj)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment