In Oracle, I could simply do this:
INSERT INTO myTable VALUES ('someValue',SYSTIMESTAMP);
That would insert two values into myTable, and one of them would be a timestamp based-on the database server's time.
For MongoDB (via the Java driver) I've tried this:
myDoc.put("value","someValue");
myDoc.put("timestamp", new Date());
myCollection.insert(myDoc);
But that creates a timestamp based-on the client machine's time, not the database server's time.
Is there a way to have MongoDB apply a timestamp to a document based-on the the database server time?
A little late to the game - but the recent releases of mongodb have $currentDate.
See http://docs.mongodb.org/manual/reference/operator/update/currentDate/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With