Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
341 stars 44 forks source link

CosmonautClient.DeleteDocumentAsync does not seem to work #65

Closed StickNitro closed 5 years ago

StickNitro commented 5 years ago

I have a generic service using the CosmonautClient and using shared collections, this is a single service with a single POST method that I then use to post Queries or Commands to the endpoint and return the relevant entity.

Everything in this setup works with the exception of the DeleteDocumentAsync method call which returns null and the subsequent query agains the same collection yields results containing the "deleted" document

var deleted = await this._cosmonautClient.DeleteDocumentAsync(this._databaseName, collectionName, message.Id, new RequestOptions { PartitionKey = new PartitionKey("id") });

Can you advise if this is a problem please?

NOTE: I have also tried getting the SelfLink and using the DocumentClient to delete the document this way but I get an exception stating the resource does not exist

Elfocrash commented 5 years ago

You need to provide the partition key value not the partition key definition when you delete. Your delete request should look like this, assuming the id is your partition key.

var deleted = await this._cosmonautClient.DeleteDocumentAsync(this._databaseName, collectionName, message.Id, new RequestOptions { PartitionKey = new PartitionKey(message.Id) });