Cosmos DB error code 400 while creating a new document

一曲冷凌霜 提交于 2019-12-11 06:01:22

问题


I've created an Azure Cosmos DB (selecting MongoDB as the language), and while creating a new document through the Azure portal (website) it fails and says:

{"code":400,"body":"Command insert failed: document does not contain shard key."}

I tried to create the following document through the website:

{
    "wordpress_id": "test"
}

And this:

{
    "id" : "replace_with_new_document_id",
    "wordpress_id": "test"
}

"wordpress_id" is a "Shard key" (or partition key) that I defined when I created the collection. It is also a Unique key.

This is what I see in the "Scale & Settings" tab. This is the error I see when I try to create the document.

Am I missing something?

Do you know why this is happening?


回答1:


Am I missing something? Do you know why this is happening?

I also could reproduce this issue if I created a shared collection from Azure portal.

According to the azure official document, we could know that we could create the shared collection with favorite tool,driver, or SDK.

With the MongoDB API, you can create a sharded collection through your favorite tool, driver, or SDK.

I do a demo with studio3t tool. The Mongo Shell I used

db.runCommand( { shardCollection: "databaseName.collectionName", key: { KeyName: "hashed" } } )

Run the Mongo Shell from the studio3t

After that we could create the document from Azure portal correctly.



来源:https://stackoverflow.com/questions/48188495/cosmos-db-error-code-400-while-creating-a-new-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!