public async Task <bool> CreateCollectionIfNotExistsAsync( string databaseId, string collectionId, string partitionKey, CosmosConsistencyLevel cosmosConsistencyLevel = CosmosConsistencyLevel.Strong, CosmosIndexingMode cosmosIndexingMode = CosmosIndexingMode.Consistent) { var database = _client.GetDatabase(databaseId); var indexingMode = GetIndexingMode(cosmosIndexingMode); var properties = new ContainerProperties(collectionId, partitionKey) { //PartitionKeyDefinitionVersion = PartitionKeyDefinitionVersion.V2, PartitionKeyPath = partitionKey, IndexingPolicy = new IndexingPolicy { Automatic = true, IndexingMode = indexingMode } }; var requestOptions = new ItemRequestOptions { ConsistencyLevel = GetConsistencyLevel(cosmosConsistencyLevel) }; var response = await database.CreateContainerIfNotExistsAsync( properties, requestOptions : requestOptions, cancellationToken : default(CancellationToken)); return(IsResponseValid(response.StatusCode)); }
public async Task <bool> CreateCollectionIfNotExistsAsync( string databaseId, string collectionId, string partitionKey, CosmosConsistencyLevel cosmosConsistencyLevel = CosmosConsistencyLevel.Strong, CosmosIndexingMode cosmosIndexingMode = CosmosIndexingMode.Consistent) { var uri = UriFactory.CreateDatabaseUri(databaseId); var requestOptions = GetRequestOptions(partitionKey, throughput: null, sharedThroughput: null, cosmosConsistencyLevel); var indexingMode = GetIndexingMode(cosmosIndexingMode); var documentCollection = GetDocumentCollection(collectionId, partitionKey, indexingMode); var response = await _client.CreateDocumentCollectionIfNotExistsAsync(uri, documentCollection, requestOptions); return(IsResponseValid(response.StatusCode)); }