Azure cosmosdb 在CosmosDB中使用PartitionKey创建集合

Azure cosmosdb 在CosmosDB中使用PartitionKey创建集合,azure-cosmosdb,Azure Cosmosdb,我想像这样使用DocumentClient在代码中创建一个集合 await client.CreateDocumentCollectionAsync ( UriFactory.CreateDatabaseUri(databaseId), new DocumentCollection { Id = collectionId }, new RequestOptions { OfferThroughput = 1000 } ); 但是如何添加PartitionKey?在Cosmos

我想像这样使用DocumentClient在代码中创建一个集合

await client.CreateDocumentCollectionAsync (
   UriFactory.CreateDatabaseUri(databaseId),
   new DocumentCollection { Id = collectionId },
   new RequestOptions { OfferThroughput = 1000 }
);

但是如何添加
PartitionKey
?在CosmosDB Emulator中,我只是在我的类中为集合添加属性的名称。我想不出来。可能是我错过了一些基本的东西。谢谢

您需要设置
DocumentCollection.PartitionKeyDefinition

DocumentCollection collectionDefinition = new DocumentCollection();
collectionDefinition.Id = collectionId;
collectionDefinition.PartitionKey.Paths.Add("/deviceId"); //--> add this

DocumentCollection partitionedCollection = await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri(databaseId),
    collectionDefinition,
    new RequestOptions { OfferThroughput = 10100 });

非常感谢。我没有足够的声望点,所以我无法提高这个分数。我想我已经做到了。再说一遍。工作得很好。