[英]Azure Cosmos DB - difference in how the partition key is supplied to query?
[英]Azure cosmos db collection is not getting the partition key
我正在尝试在我的c#
代码中创建一个Azure Blue Cosmos数据库和集合。
await client.CreateDatabaseIfNotExistsAsync(new Database() { Id = "data"});
DocumentCollection dCollection = await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("data"), new DocumentCollection { Id = "coll"}, new RequestOptions { OfferThroughput = 400, , PartitionKey = new PartitionKey("/id") });
// dashboardCollection.PartitionKey.Paths.Add("/id");
当我转到portal.azure.com
并检查我的文档数据库时,便创建了该集合。 当我转到集合的Scale and Settings
,没有看到分区键。
我手动创建了另一个集合,它在“ Scale and Settings
部分显示了分区键。
由于此分区键错误, delete
功能引发错误
将ID为1
的记录成功插入到文档DB中。 以下删除失败,表明partitionKey
无效。
ResourceResponse<Document> response = await client.DeleteDocumentAsync(UriFactory.CreateDocumentUri("data", "coll", "1"), new RequestOptions { PartitionKey = new PartitionKey("1") });
我来自CosmosDB工程团队。
创建DocumentCollection时,请确保在DocumentCollection对象中提供了分区键,如下所示:
PartitionKeyDefinition pkDefn = new PartitionKeyDefinition() { Paths = new Collection<string>() { "/id" } };
DocumentCollection dCollection = await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("data"), new DocumentCollection { Id = "coll", PartitionKey = pkDefn }, new RequestOptions { OfferThroughput = 400, PartitionKey = new PartitionKey("/id") });
在收集CRUD请求期间,不接受RequestOptions上的PartitionKey,因为我们希望PartitionKey成为收集对象的一部分。 在文档CRUD请求期间,将接受RequestOptions上的PartitionKey。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.