Created
March 4, 2018 10:17
-
-
Save urtens/aa4fff72cf9969cfd61682663b49c59f to your computer and use it in GitHub Desktop.
MongoDB: Get document insertion date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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