Deleting documents
In this section, we will demonstrate how to delete a document from your collection. DocumentDB does not support deleting batches of documents or a whole range of documents. You need to delete them one by one, using the SelfLink
property.
The following code snippet demonstrates how to delete a single document:
var documentByLinqToObjects = client.CreateDocumentQuery<PersonInformation>(collection.DocumentsLink) .Where(personInformation => personInformation.FirstName.Equals("Riccardo") && personInformation.LastName.Equals("Becker")).AsEnumerable<PersonInformation>().First(); ////if the document exists, delete it and recreate it. if (null != documentByLinqToObjects) { await client.DeleteDocumentAsync(documentByLinqToObjects.SelfLink); }
Deleting a whole range of documents (if the query returns multiple documents) is not yet possible in one call. This is because we need the SelfLink
property to the document in order...