O'Reilly logo

Guide to NoSQL with Azure Cosmos DB by Daron Yondem, Gaston C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying and creating document collections

The following lines declare the code for the CreateCollectionIfNotExistsAsync asynchronous static method, which creates a new document collection if a collection with id equal to the value stored in the collectionId field doesn't exist in the database. Add the following lines to the existing code of the Program.cs file. The code file for the sample is included in the learning_cosmos_db_04_01 folder in the dot_net_core_2_samples/SampleApp1/SampleApp1/Program.cs file:

private static async Task<DocumentCollection> CreateCollectionIfNotExistsAsync() { var databaseUri = UriFactory.CreateDatabaseUri(databaseId); DocumentCollection documentCollectionResource; var isCollectionCreated = await client.CreateDocumentCollectionQuery(databaseUri) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required