Reputation: 1056
I am storing a table in Azure cosmos DB
which has a lot of partitions. I want to query content only for those partitions which had any update in last X minutes. Is there a way to efficiently query the list of partition keys which were updated in last X minutes? - Since cross partition queries can turn out to be really expensive.
Upvotes: 0
Views: 334
Reputation: 8763
One way to do this efficiently is to store the last update time in it's own container with a single logical partition and a composite index with desc sort on your lastUpdated
property.
{
"id": "xxxx",
"pk": "0000",
"pkValue": "pk value from other container",
"lastUpdated": "2020-06-21T23:14:25.7251173Z"
}
Make sure you use the ISO 8601 UTC standard for datetime strings, see DateTime in Cosmos DB. Also see docs on Composite Indexes
The question to answer though is whether this is more cost efficient than doing cross partition queries. If as you say there is a lot of data across many physical partitions then it likely could be. This you will have to determine though.
Hope this is helpful.
Upvotes: 1