I want to query all the documents in a collection to get the timestamp of each document from the ObjectID, as there is no separate createdAt fieldin the documents. How do i structure the query for the same in java?
Asked
Active
Viewed 660 times
1
-
Here it is: https://docs.mongodb.com/manual/reference/method/ObjectId.getTimestamp/#ObjectId.getTimestamp also https://gist.github.com/tebemis/0e55aa0089e928f362d9, – dkb Jul 03 '18 at 10:15
-
Your question was already answered here: https://stackoverflow.com/questions/45296105/how-to-read-date-timestamp-from-mongodb-using-java – m.rp Jul 03 '18 at 10:17
-
@ManuelRapino The question is different the user already has a date field in her document. – Emma Vaze Jul 03 '18 at 10:21
-
@dkb I've already gone through the document. But I'm not understanding how to pass it to a query. And the other link works for Js. – Emma Vaze Jul 03 '18 at 10:27
-
Hi @EmmaVaze, could you clarify what are you intending to do ? Your question implies that you would like to retrieve timestamp value, but your comment suggest that you would like to query using the timestamp. Perhaps a rough example of query would be useful. – Wan B. Jul 04 '18 at 04:23
-
@WanBachtiar I'm trying to retrieve the timestamp from the object id for the documents in a collection in java. – Emma Vaze Jul 04 '18 at 17:15