Skip to content

Instantly share code, notes, and snippets.

@urtens
Created March 4, 2018 10:17
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 urtens/aa4fff72cf9969cfd61682663b49c59f to your computer and use it in GitHub Desktop.
Save urtens/aa4fff72cf9969cfd61682663b49c59f to your computer and use it in GitHub Desktop.
MongoDB: Get document insertion date
db.collection.find().sort({ts: 1}).limit(1).forEach(function (doc){ d = doc._id.getTimestamp(); 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