创建新文档时出现Cosmos DB错误代码400 [英] Cosmos DB error code 400 while creating a new document

查看:96
本文介绍了创建新文档时出现Cosmos DB错误代码400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了Azure Cosmos数据库(选择MongoDB作为语言),并且在通过Azure门户(网站)创建新文档时失败了,并说:

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"
}

这:

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

"wordpress_id"是创建集合时定义的"Shard key"(或分区键).这也是一个唯一键.

"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.

我错过了什么吗?

你知道为什么会这样吗?

Do you know why this is happening?

推荐答案

我错过了什么吗?你知道为什么会这样吗?

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

如果我从Azure门户创建共享集合,我也可以重现此问题.

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

根据天蓝色官方文件,我们知道可以使用常用工具,驱动程序或SDK 创建共享集合.

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

使用MongoDB API,您可以通过收藏的工具,驱动程序或SDK 创建分片集合.

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

我使用 studio3t 工具进行了演示.我用过的Mongo Shell

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

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

从studio3t运行Mongo Shell

Run the Mongo Shell from the studio3t

之后,我们可以从Azure门户正确创建文档.

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

这篇关于创建新文档时出现Cosmos DB错误代码400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆