C# Azure cosmos db集合未获取分区密钥

C# Azure cosmos db集合未获取分区密钥,c#,azure,azure-cosmosdb,C#,Azure,Azure Cosmosdb,我正在尝试在我的c#code中创建azure cosmos数据库和集合 await client.CreateDatabaseIfNotExistsAsync(new Database() { Id = "data"}); DocumentCollection dCollection = await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("data"), new DocumentC

我正在尝试在我的
c#
code中创建azure 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
部分显示分区键

由于分区键错误,
delete
函数正在抛出错误

将id为
1
的记录成功插入文档数据库。以下删除操作失败,说明
分区键
无效

ResourceResponse<Document> response = await client.DeleteDocumentAsync(UriFactory.CreateDocumentUri("data", "coll", "1"), new RequestOptions { PartitionKey = new PartitionKey("1") });
resourcesponse response=wait client.deleteDocumentSync(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") });
PartitionKeyDefinition pkDefn=new PartitionKeyDefinition(){path=new Collection(){“/id”};
DocumentCollection dCollection=await client.CreateDocumentCollectionIfNoteExistsAsync(UriFactory.CreateDatabaseUri(“数据”),new DocumentCollection{Id=“coll”,PartitionKey=pkDefn},new RequestOptions{OfferThroughput=400,PartitionKey=new PartitionKey(“/Id”);

RequestOptions上的PartitionKey在收集CRUD请求期间不受尊重,因为我们希望PartitionKey是收集对象的一部分。在文档CRUD请求期间,RequestOptions上的PartitionKey将得到尊重。

与您的答案相关的几个问题。由于我们必须提供分区密钥id,Azure门户是否会像您今天描述的那样创建一个集合?如何在ReadDocumentSync中引用分区键的值?我得到的只是具有指定id的实体不存在。