private static void CreateDocumentCollection(DocumentClient client, string databaseName, DocumentCollectionConfig collectionConfig) { DocumentCollection collectionInfo = new DocumentCollection() { Id = collectionConfig.collectionName, PartitionKey = new PartitionKeyDefinition() { Paths = { collectionConfig.PartitionKeyPath } } }; // Configure collections for maximum query flexibility including string range queries. collectionInfo.IndexingPolicy = collectionConfig.indexingPolicy ?? new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 }); try { // Here we create a collection with 400 RU/s. var result = client.CreateDocumentCollectionAsync( UriFactory.CreateDatabaseUri(databaseName), collectionInfo, new RequestOptions { OfferThroughput = collectionConfig.offerThroughput }).Result; var x = result.Resource; } catch { throw; } }
public static async Task CreateDocumentCollectionIfNotExists(DocumentClient client, string databaseName, DocumentCollectionConfig collectionConfig) { HttpStatusCode?returnCode; try { await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionConfig.collectionName)); } catch (DocumentClientException de) { returnCode = de.StatusCode; // If the document collection does not exist, create a new collection if (de.StatusCode == HttpStatusCode.NotFound) { CreateDocumentCollection(client, databaseName, collectionConfig); } else { throw; } } }