开发者

mongodb date mongolian deadbeef

I'm using the mongolian deadbeef client for node.js

I have a document like this:

{
  "time": 1308651397345,
  "_id": {
      "$oid": "4e006f853d93e4676e00000a"
  }
}

But when I access it with the mongolian deadbeef client, I see:

{ 
  time: { low_: -1313627935, high_: 304 },
  _id: 4e006f853d93e4676e00000a 
}

How do I access the correct time?

Than开发者_运维技巧ks


Be aware that Mongo ObjectIds contain the timestamp within them. It would save space just to use the _id.

I've never used node.js or mongolian beef. However, this works from the mongo client

> var foo = new ObjectId()                                            
> foo.getTimestamp()                                                  
ISODate("2012-08-06T12:58:15Z")                                       
> foo.getTimestamp                                                    
function () {                                                         
    return new Date(parseInt(this.toString().slice(0, 8), 16) * 1000);
}                                                                     

The last part shows you how you can implement getTimeStamp() yourself.

Finally be aware that 10gen has released an officially supported node.js driver.


Try time.toNumber(), what you see is a 64 bit long being split into two 32 bits ints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜