how to Convert Oplog Timestamp into ISO Date-time

1,065 views
Skip to first unread message

Muhammed Fazil

unread,
Oct 14, 2014, 3:55:53 AM10/14/14
to mongod...@googlegroups.com
When i fetched the timestamp of operation i got is as "
ts" : Timestamp(1412767541, 1)
How can i convert into ISO date-time by which the operation happended??
Thankyou..

Will Berkeley

unread,
Oct 14, 2014, 12:02:29 PM10/14/14
to mongod...@googlegroups.com
The Timestamp value as displayed in the shell has the format Timestamp(<time_t>, <ordinal>), where time_t is a32-bit value indicating seconds since the unix epoch and the 32-bit ordinal value is for ordering operations occurring in the same second. To convert to a Date object representing the datetime at which the operation happened, in the shell,

> x
Timestamp(1413302103, 1)
> x.t
1413302103
> new Date(x.t * 1000)
ISODate("2014-10-14T15:55:03Z")

The * 1000 is necessary because Date() expects milliseconds. For more: Timestamp BSON type. Keep in mind Timestamp is meant just for internal MongoDB use and in your own data you should prefer the Date type.

-Will
Reply all
Reply to author
Forward
0 new messages