MongoDB : Convert Oplog timestamp into ISO date

Most easy way to figure out the recent changes (any DB any collection) in mongo Database is to query to Oplog with sorting on timestamp

> db.oplog.$main.find().sort({“ts”:-1}).limit(5)

Output : { “ts” : Timestamp(1457990841, 1), “op” : “i”, “ns” : “nis.devices”, “o” : { “_id” : ObjectId(“56e72cb9389c38c2aeeab698”), “name” : “premaseemmarch” } }

This would show 5 recent records in any collection operated in the database.(we just sorted by time stamp in reverse order) To verify the the date we might have to convert the Timestamp in ISO date. -> “ts” : Timestamp(1457990841, 1)

Way 1 : 

> new Date(1000* 1457990841)

ISODate(“2016-03-14T21:27:21Z”)

Way 2 : 

> x = Timestamp(1457989386, 1)

Timestamp(1457989386, 1)

> new Date(x.t * 1000)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s