I had been banging my head against the wall trying to insert documents into partitioned collections in a Mongo API CosmosDB when the collection was created with the API, I was finally able to get my answer using this link:
ComosDB - MongoAPI - Document does not contain shard key
But the solution just raised more questions for me. My issue was that if I tried to create a partition key on /genericKey the creation of the collection would work fine, but when I would try to insert I got the error "does not contain shard key"
When I would create it from within the mongo client or within the portal it worked fine. I finally realized by running "az cosmosdb collection show" against my collecitons that on the ones created using the portal and the mongo client, the partition key path was actually "/'$v'genericKey/'$v'" and on the ones that I created using the CLI it was just "/genericKey"
So my workaround was to put the full string of "/'$v'genericKey/'$v'" into my CLI command, my question is what is the significance of the /'$v'at the beginning and the end? Why do I have to add it?