Several months ago, I started managing a non-relational DocumentDB database (new CosmosDB) on Azure. I had to delete some records, then I encountered some difficulties. The use of partitions and selecting the correct partition by ID was very important. So, I created the following Windows console application sample with c# which collects the document IDs based on a query and then deletes the documents for these IDs.
Initially we install the libraries Microsoft.Azure.DocumentDB and Newtonsoft.Json.

In order to connect the DocumentDB database with the Windows console application, you need the credentials (uri + primary key), which are on the “keys” Tab on Azure.

Next, you initialize the documentDB uri, primary key, name of the collection and the name of the database.
private const string connectionEndpointUri ="https://dropdocuments.documents.azure.com:443/";
private const string primaryKey = "Kl9XbLDeSPjcmoJra7tKkHblfamvhmxFdzcw7LN3Pl44ENCdBYHax6krgmqGgqfpRbUEj73Rml0YAOR2ALJBZg==";
private static string databaseId = @"DatabaseName";
private static string collectionId = @"CollectionName";
private Uri collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
Read More »