How to get latest document created in Azure DocumentDB

Viewed 1020

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?

1 Answers

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.

Related