From Date to Timestamp in JavaScript/Node.js?

86 views
Skip to first unread message

Jeremy Darling

unread,
Jul 30, 2015, 2:37:40 PM7/30/15
to mongodb-user
What is the proper way to convert from a Date() object to a valid Timestamp?

I thought it would be something similar to:

var dateToTimestamp = function(data){
    return Timestamp(0, data.getTime() / 1000 | 0);
};

But this doesn't compare appropriately when I try to use it against the oplog.ts value.  The oplog value has the high bits set while my conversion of course doesn't have them.  So I end up getting everything from the oplog instead of only things after my expected date/time.

Thanks,
 - Jeremy

Jeremy Darling

unread,
Jul 30, 2015, 2:57:35 PM7/30/15
to mongod...@googlegroups.com
Never mind, just realize the API changed on the library I was using and instead of passing in the Timestamp Object I should have been passing in the integer value of the high byte :(

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/nnDm9yaGkHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1b40a32e-036f-4920-902d-ca22174f816d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages