Reputation: 83
How can I retrieve the latest document that was added to a collection in Azure DocumentDB? Is there a built-in mechanism or should I create a DateTime / auto-incremented ID property?
Upvotes: 3
Views: 1083
Reputation: 71055
Cosmos DB DocumentDB documents have a _ts
property, which is updated whenever a document is created or updated. So you could query on that property.
However: If you only want creation time, and not update time, you'd need to store your own timestamp property upon document insert, and then query on that property.
By default, all properties are indexed, so you should be able to query on descending order, on timestamp.
Upvotes: 4