Converting a mongo stored date back into milliseconds since Unix epoch when loaded?

前端 未结 5 435
名媛妹妹
名媛妹妹 2020-12-15 21:09

I am using Mongoose & Node.js for my webserver.

As a part of one of my document schemas, I have a \'timestamp\' field. The line for it in the schema is:

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 21:30

    This works fine for me

    db.eurusd.ticks.findOne({_id:ObjectId("518636777055000000000000")}).t.getTime()
    

    returns time in miliseconds, where returned document has structure

    {
     "_id" : ObjectId("518636777055000000000000"),
     "t" : ISODate("2013-05-05T10:37:43Z"), // date data type
     "ask" : "Joe",
     "bid" : 33
    }
    

提交回复
热议问题