I have one application that posts messages to Cosmos DB by reading messages from another application database. The only information I can get from other app is documentId i.e. primary key from the app database and the body of the message. Structure is something as below:
{
"id":<documentid>,
"body":<body picked up from App>,
"Timestamp":<today's date time>
}
Body contains simple text message like "Hello World! Today is Wednesday". I have the following requirements: 1. Need to query document by documentId. 2. Need to query documents between two date/time stamps.
In this scenario, how can we identify a partition key for the container to retrieve documents easily by the two criterion specified above?
Any inputs are highly appreciated.
For querying by id: If you know the id, you can do a direct read (vs a query). This requires knowing both the id and the partition key; if this is your primary method of retrieval, you can set your partition key to /id
and this becomes the most straightforward approach (and the least expensive, RU-wise).
For querying between timestamps: You'll need to rethink partitioning, since you'd end up doing cross-partition queries if using /id
as your partition key. There's really no "right" answer to this part, as we just don't know enough about your app and your query patterns (or volume of data in terms of transaction rate, size, etc). Just know that, if you partition your data, you'll ideally want to limit your queries to be within a single logical partition; otherwise you'll need to perform cross-partition queries, which will cost more RU.