I created a CosmosDB database that uses MongoDB's Python SDK, let's call the database as school
and the collection as students
. While creating the database, the Azure UI asked me to create a shard key for unlimited storage capacity, let's call it school.students
.
I am using pymongo
to add the following document:
{
"id": "abc123",
"name": "jack"
}
and the code as:
from pymongo import MongoClient
student_data = {
"id": "abc123",
"name": "jack"
}
client = MongoClient("mongodb://...")
db = client["school"]
collection = db["students"]
collection.insert_one(student_data)
When I chose the storage with 10GB, I have no problem adding the document, but when I chose the unlimited option with shard key, I get the following error:
pymongo.errors.WriteError: document does not contain shard key at 'school.students'
Question is, where should I use the shard key? and how to get over this?