Reputation: 669
I have a cosmos db document collection which contains different kinds of documents, but sharing same partition keys. Is there a way to update document with same partition key, but different document type via C#? In all the examples I have seen, deleting/updating a document requires a unique partition key/document uri. But, in my case there are 3 documents with same partition key.
Below is a collection(borrowed from https://learn.microsoft.com/en-us/azure/cosmos-db/modeling-data) with 2 types of documents partitioned by 'bookId'.
I would like to know if there is a way to update/delete documents using partition key and a type/other criteria.
Example1: Update document with bookId: "b1", type: "review" and id: "r1"
Example2: Delete all documents with bookId: "b1"
Book documents:
{
"id": "b1",
"name": "Azure Cosmos DB 101",
"bookId": "b1",
"type": "book"
}
Review documents:
{
"id": "r1",
"content": "This book is awesome",
"bookId": "b1",
"type": "review"
},
{
"id": "r2",
"content": "Best book ever!",
"bookId": "b1",
"type": "review"
}
Upvotes: 0
Views: 743
Reputation: 8763
Cosmos does not support set-based insert/update/delete operations. You must call these operations individually from your client or you can write a stored procedure and pass in whatever is needed to find the relevant data but you're still going to call those operations individually, just server side.
Examples:
Hope this is helpful.
Upvotes: 2