1

I am trying to convert oplog ts field to unix epoch time.

oplog document

{
    "ts" : Timestamp(6454921106666029, 1),
    "t" : NumberLong(2),
    "h" : NumberLong(-7592058469580740624),
    "v" : 2,
    "op" : "n",
    "ns" : "",
    "o" : {
        "msg" : "periodic noop"
    }
}

When I run python utility, I am getting below output

python -c 'import util; print util.long_to_bson_ts(6454921106666029)'
Timestamp(1502903, 1872605741)

https://github.com/mongodb-labs/mongo-connector/issues/324

Not sure how to read oplog timestamp in 3.4.

Thanks Pari

Pari
  • 1,443
  • 3
  • 19
  • 34
  • If you are using python then there is a [`Timestamp`](https://api.mongodb.com/python/current/api/bson/timestamp.html) type from which you can get the epoch milliseconds or a `datetime` object. Same really applies to your language of choice, since there is a type provided in the bson library that exists for every language implementation. – Neil Lunn Aug 17 '17 at 11:22
  • See also the general definition of [`Timestamp`](https://docs.mongodb.com/manual/reference/bson-types/#timestamps) *"the first 32 bits are a time_t value (seconds since the Unix epoch)"* which basically means that the first number x 1000 is the *milliseconds since epoch* which is used as a common date constructor. – Neil Lunn Aug 17 '17 at 11:31
  • 1
    I am not restricted to python. When I searched over google, I found util.py but that is not giving correct result. How do I extract human readable timestamp from 6454921106666029. Thanks – Pari Aug 17 '17 at 13:15

0 Answers0