I am experimenting with MongoDB Api for CosmosDB and I have the following error while inserting a value in the database :
Command insert failed: document does not contain shard key.
I'm using cosmosdb emulator, My Partition Key is "Id" Here is a simple insert I tried :
mongoCollection.InsertOne(new { Name = "John", Id = 007 });
To resolve this issue, I searched and saw this question :
I tried running the command specified in the answer to the question, as follows :
var command = new BsonDocument("{ shardCollection: \"Mydb.collection1\", key: { Id: \"hashed\" } }", 1);
database.RunCommand<BsonDocument>(command);
But it doesn't work and throws me another exception, Please can someone tell me what to do ?