private async Task CreateContainerIfNotExistsAsync() { try { // Create new container var containerProperties = new ContainerProperties { Id = Configuration.Collection.CollectionName, PartitionKeyPath = "/id", DefaultTimeToLive = -1 }; await DatabaseV3.CreateContainerIfNotExistsAsync(containerProperties); await DocumentClient.ReadDocumentCollectionAsync(DocumentCollectionUri); } catch (DocumentClientException e) { if (e.StatusCode == System.Net.HttpStatusCode.NotFound) { await DocumentClient.CreateDocumentCollectionAsync( DatabaseUri, new DocumentCollection { Id = Configuration.Collection.CollectionName }, new Microsoft.Azure.Documents.Client.RequestOptions { OfferThroughput = Configuration.Collection.ReserveUnits, }); } else { throw; } } }
protected async Task CreateContainerIfNotExistsAsync(Collection collection) { // Create new container var containerProperties = new ContainerProperties { Id = collection.CollectionName, PartitionKeyPath = GetPartitionKeyPath(), // "/id" DefaultTimeToLive = -1, IndexingPolicy = new Microsoft.Azure.Cosmos.IndexingPolicy() { IndexingMode = Microsoft.Azure.Cosmos.IndexingMode.Lazy, Automatic = true } }; var containerResponse = await DatabaseV3.CreateContainerIfNotExistsAsync(containerProperties); if (!containerResponse.StatusCode.IsSuccess()) { var message = $"Cant Create CosmosContainer. Database:{DatabaseV3.Id}, Container:{collection.CollectionName}"; _logger.LogError(message); throw new Exception(message); } //await DatabaseV3.CreateContainerIfNotExistsAsync(containerProperties); }
protected async Task CreateContainerIfNotExistsAsync(Collection collection, Uri documentCollectionUri) { // Create new container var containerProperties = new ContainerProperties { Id = collection.CollectionName, PartitionKeyPath = "/id", DefaultTimeToLive = -1 }; var containerResponse = await DatabaseV3.CreateContainerIfNotExistsAsync(containerProperties); if (!containerResponse.StatusCode.IsSuccess()) { var message = $"Cant Create CosmosContainer. Database:{DatabaseV3.Id}, Container:{collection.CollectionName}"; _logger.LogError(message); throw new Exception(message); } }