Adventures with Cosmos: Delete All Documents
using System; | |
using Microsoft.Azure.Cosmos; | |
using System.Collections; | |
using System.Collections.Generic; | |
CosmosClient cosmosClient = new CosmosClient(Cosmos.Endpoint, Cosmos.Key); | |
Microsoft.Azure.Cosmos.Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync("teamaloo"); | |
var containers = new Dictionary<string, string>(); | |
containers.Add("YOUR_CONTAINER_1", "/YOUR_PARTITION_KEY_1"); | |
containers.Add("YOUR_CONTAINER_2", "/YOUR_PARTITION_KEY_2"); | |
foreach(var c in containers) | |
{ | |
try | |
{ | |
var container = database.GetContainer(c.Key); | |
Display.AsMarkdown("Deleting `" + c.Key + "`..."); | |
await container.DeleteContainerAsync(); | |
} | |
catch | |
{ | |
} | |
Display.AsMarkdown("Creating `" + c.Key + "`..."); | |
await database.CreateContainerIfNotExistsAsync(c.Key, c.Value); | |
Display.AsMarkdown("Created `" + c.Key + "`."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment