The ObjectId used as the default key in mongodb documents has embedded timestamp (calling objectid.generation_time returns a datetime object). So it is possible to use this generation time instead of keeping a separate creation timestamp? How will you be able to sort by creation time or query for the last N items efficiently using this embedded timestamp?
The ObjectId used as the default key in mongodb documents has embedded timestamp (calling
Share
I suppose since MongoDB ObjectId contain a timestamp, you can sort by ‘created date’ if you will sort by objectId:
And if you want last 30 created items you can use following query:
I am actualy not sure,i just suppose that ordering by _id should work as described above. I’ll create some tests later.
Update:
Yes it is so. If you order by _id you will automatically order by _id created date.
I’ve done small test in c#, mb someone interest in it: