can I delete document from azure cosmos db using sql query, without using any sdk.

Narayan, Deepak 6 Reputation points
2022-04-14T07:19:25.117+00:00

delete from c where c.id="someid"

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,469 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Anurag Sharma 17,576 Reputation points
    2022-04-15T06:34:34.277+00:00

    Hi @Narayan, Deepak , welcome to Microsoft Q&A forum.

    As rightly mentioned by @Sam Cogan , we cannot directly delete the documents using queries. However we can create a stored procedure as mentioned in the below link and then by executing the procedure we can delete the documents scoped to a partition key:

    Stored Procedure for bulk deleting the documents

    Then just execute the procedure as mentioned with parameters. Partition key was city in this container.

    SELECT * FROM c WHERE c.city= 'mumbai'  
    

    193332-image.png

    Please let us know if this helps or else we can discuss further on the same.

    ----------

    If answer helps, you can mark it 'Accept Answer'

    4 people found this answer helpful.

  2. Sam Cogan 10,322 Reputation points MVP
    2022-04-14T09:22:07.753+00:00

    No, the SQL API does not provide facilities for delete, this must be done through the REST API, Storage Explorer etc.


  3. Todd Liu 0 Reputation points Microsoft Employee
    2023-02-21T08:45:55.53+00:00

    You could use the following Gremlin query to remove given items. Notice that you are accessing NonSQL data as Graph, so that only a few fundamental properties are visible, i.e., partition key, unique id and label (label is always 'NativeVertex' here).

    g.V().has('id', within(idsToDelete)).drop()
    
    0 comments No comments