问题
I want to create a Collection in Code using the DocumentClient like this
await client.CreateDocumentCollectionAsync (
UriFactory.CreateDatabaseUri(databaseId),
new DocumentCollection { Id = collectionId },
new RequestOptions { OfferThroughput = 1000 }
);
But how do I add a PartitionKey
? In the CosmosDB Emulator I just add the name of the property on my class for the collection. Cant work it out. Could be I'm missing something fundamental here. Thank you
回答1:
You need to set 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 });
来源:https://stackoverflow.com/questions/48261296/create-a-collection-with-partitionkey-in-cosmosdb