Reputation: 6790
I was supprised to learn that ObjectId("507c7f79bcf86cd7994f6c0e").getTimestamp()
returned according to the mongodb.org website ISODate("2012-10-15T21:26:17Z")
So my question is if this ObjectID is it the MongoID? or are they two separate things.
The reason I ask is currently when a user post a status to our site we use time() function in PHP to store the time that the user posted the status, it would save us a little bit of code if we were able to use the mongoID to get the time and date that the status was uploaded.
I am interested in whether I am understanding this correctly.
I would also be interested in a PHP example on how I would get the MongoID to output as the date and time.
Upvotes: 0
Views: 869
Reputation: 36214
So my question is if this ObjectID is it the MongoID?
Mongodb identifies documents by their _id
field. If you not supply an _id
field at insertion, the mongodb server will generate an ObjectId
for that document (into its _id
field). In php, these values will be converted to the MongoId
class.
... if we were able to use the mongoID to get the time and date that the status was uploaded.
Maybe. ObjectId
s are constructed using a 4-byte value representing the seconds since the Unix epoch. If you don't supply an _id
field at insertion (or you supply an ObjectId
value, generated by your client application, using MongoDB's supplied api for that), ObjectId
s can be used for that. But, you are not forced to use ObjectId
at every _id
field (or at all). Also (because they represented in 4 bytes) they are affected by the year 2038 problem ...
Upvotes: 1