In this bankruptcy, we are able to discover ways to delete a record from your DocumentDB account. Using Azure Portal, you could easily delete any report by beginning the report in Document Explorer and click on the ‘Delete’ alternative.
It will show the affirmation message. Now press the Yes button and you will see that the document is now not available in your DocumentDB account.
Now while you need to delete a file using .Net SDK.
Step 1 − It's the identical pattern as we've visible earlier than where we're going to query first to get the SelfLinks of each new document. We don't use SELECT * right here, which would return the files in their entirety, which we don't need.
Step 2 − Instead we're simply selecting the SelfLinks into a list and then we simply call DeleteDocumentAsync for each SelfLink, one after the other, to delete the files from the gathering.
private async static Task DeleteDocuments(DocumentClient client) {
Console.WriteLine();
Console.WriteLine(">>> Delete Documents <<<");
Console.WriteLine();
Console.WriteLine("Quering for documents to be deleted");
var sql =
"SELECT VALUE c._self FROM c WHERE STARTSWITH(c.name, 'New Customer') = true";
var documentLinks =
client.CreateDocumentQuery<string>(collection.SelfLink, sql).ToList();
Console.WriteLine("Found {0} documents to be deleted", documentLinks.Count);
foreach (var documentLink in documentLinks) {
await client.DeleteDocumentAsync(documentLink);
}
Console.WriteLine("Deleted {0} new customer documents", documentLinks.Count);
Console.WriteLine();
}
Step 3 − Now allow’s name the above DeleteDocuments from the CreateDocumentClient venture.
private static async Task CreateDocumentClient() {
// Create a new instance of the DocumentClient
using (var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey)) {
database = client.CreateDatabaseQuery("SELECT * FROM c WHERE c.id =
'myfirstdb'").AsEnumerable().First();
collection = client.CreateDocumentCollectionQuery(database.CollectionsLink,
"SELECT * FROM c WHERE c.id = 'MyCollection'").AsEnumerable().First();
await DeleteDocuments(client);
}
}
***** Delete Documents *****
Quering for documents to be deleted
Found 2 documents to be deleted
Deleted 2 new customer documents