Closed tlanda closed 5 years ago
On initial investigation it appears the REST API documentation for collections (https://docs.microsoft.com/en-us/rest/api/cosmos-db/collections) has not been updated yet with information on how to set Unique Keys.
I could probably do some reverse engineering on the Azure Cosmos DB .NET Core SDK, but it hasn't been open sourced yet (https://github.com/Azure/azure-cosmosdb-dotnet/tree/master/sdk). Definitely possible to do, but will require more digging.
Update: I've reached out to the MVP community and Cosmos DB team to see if there is any documentation available on this. Hopefully they'll just be able to quickly update the documentation.
Update: I got some great info from the Cosmos DB team and MVPs. To create a unique policy we must add the following into the collection body:
"uniqueKeyPolicy": {
"uniqueKeys": [
{ "paths": [ "/name", "/address "] },
{ "paths": [ "/email" ] }
]
}
And:
coll = {"id": "collection_unique_keys", 'uniqueKeyPolicy': {'uniqueKeys': [{'paths': ['/field1/field2', '/field3']}]}}
@tlanda - I've finished work on this and am just finishing up the integration tests on this now. I'll have this out in the next release later on this week.
Great, thank you very much!
A pleasure! Just releasing this to the PSGallery now as 2.1.12. Check there tomorrow.
Published to gallery here: https://www.powershellgallery.com/packages/CosmosDB/2.1.12.137
Documentation on how to use it in the Wiki: https://github.com/PlagueHO/CosmosDB/wiki#creating-a-collection-with-a-custom-unique-key-policy
Would you consider to support creating Collections with with a unique key policy? https://docs.microsoft.com/en-us/azure/cosmos-db/unique-keys