'Bulk Delete Cosmos DB operations using javascript stored procedure where partitionkey is blank / ""
I'm attempting to use the below JS stored procedure to bulk delete documents in Cosmos DB (Document DB) from Azure Portal / Data Explorer. It is working for non-blank partitionKey values however it is not when the value is = "".
The stored procedure asks for a mandatory partitionKey value (as expected) and while it accepts a blank field, it won't identify records correctly (returns "deleted": 0). The equivalent ad-hoc SELECT query identifies the record successfully.
I have tried specifying partitionKey into request options adding one of below, but to no avail:
partitionKey : ""
partitionKey : null
partitionKey : {}
partitionKey : undefined
Solution 1:[1]
You can't delete the documents unless you have the partition key. When you execute a stored procedure in a partitioned collection, you must provide the partition key.
Stored procedures are best suited for tasks that involve a transaction across a partition key value. When determining whether to employ stored procedures, optimize by encapsulating as many writes as possible. In general, stored procedures are not the most efficient way to perform large numbers of read or query operations, therefore utilizing them to batch huge numbers of reads to return to the client would not deliver the desired advantage. These read-heavy activities should be performed on the client side, using the Cosmos SDK, for the optimum speed.
Setting the partition-key to Undefined Value will not allow you to get around the above rule.
Please see some official document information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PratikLad-MT |
