1
votes

I am trying to create a stored procedure to delete documents in Cosmos Db by using a query. Once the query returns the documents, I would like all the documents to be deleted.

I tried using the script from this website but this requires putting one partition key. My Cosmos collection has a separate partition key per document so it will not work

This is an example of a query I would like to run

SELECT c.currentTime, c.pastTime 
FROM C 
WHERE c.currentTime < c.pastTime

If that satisfies, I would like to delete all the results from that query.

Is there a way create a stored proc or modify the one in the website provided so it loops through all the collection instead of specifying one partition key?

1
how can you have separate partition key per document?Sajeetharan

1 Answers

1
votes

Is there a way create a stored proc or modify the one in the website provided so it loops through all the collection instead of specifying one partition key?

The quick answer is no,please see some official statements:

1.I answered similar cases before, they all want to avoid such partition key requirement when executing SP.However,it can't be avoided.

Azure Cosmos DB asking for partition key for stored procedure

Cosmos DB Stored procedure did not execute without PartitionKey

If the collection the stored procedure is registered against is a single-partition collection, then the transaction is scoped to all the documents within the collection. If the collection is partitioned, then stored procedures are executed in the transaction scope of a single partition key. Each stored procedure execution must then include a partition key value corresponding to the scope the transaction must run under.

2.Above statement and link have been modified into below new document:

enter image description here

3.You could follow official suggestion to get an idea of Bulk Executor Lib SDK. I found BulkDelete feature in this source code,please try it.