Skip to content

Instantly share code, notes, and snippets.

@faisal00813
Last active February 7, 2017 14:13
Show Gist options
  • Save faisal00813/d1e22d31aa7dbee956ae8c690ea1530c to your computer and use it in GitHub Desktop.
Save faisal00813/d1e22d31aa7dbee956ae8c690ea1530c to your computer and use it in GitHub Desktop.
Query for updating the timesatamp in document extracted from _Id field
db['your-collection'].find().forEach(function (doc){
d = doc._id.getTimestamp();
doc.visitedOn = d;
db['your-collection'].update({"_id":doc._id},doc,{upsert:true});
print(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment