1

I'm able to delete the document in cosmosdb using the below code.

Optional<Place> place = repository.findById(id);
repository.delete(place.get());

But, if I use the method repository.deleteById(id) from the CrudRepository it's returning me the below error.

com.azure.data.cosmos.NotFoundException: ["Resource Not Found"]
David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Can you include some code here? – Mark Brown May 02 '20 at 17:08
  • Optional place= repository.findById(id); – Karthik Bashyam May 02 '20 at 17:58
  • @KarthikBashyam - please edit your question to include relevant code (and please include more than just a single line, as there's really not enough to go on: maybe include relevant data, as well as your code you're using for deleting a document (your comment only shows how you looked up a document). Please avoid putting code within comments; it's harder to read your question this way, and also it's very difficult to properly format code when it's posted as a comment. – David Makogon May 03 '20 at 01:06
  • Hello David. Updated the code. – Karthik Bashyam May 03 '20 at 01:25

1 Answers1

2

You should pass the partition key to the deleteById method. Use the following method from CosmosRepository:

void deleteById(ID id, PartitionKey partitionKey);
     yourRepository.deleteById(id,new PartitionKey(<parition key value>));

The following works because the the argument has the ID and Partition key values.

repository.delete(place.get());

Additionally, Use the following method from CosmosRepository for find a document by ID.

Optional<T> findById(ID id, PartitionKey partitionKey);

If your IDs are not unique across partitions then you might get inconsistent results.

RCT
  • 1,044
  • 1
  • 5
  • 12