首页 文章

创建新文档时Cosmos DB错误代码400

提问于
浏览
1

我创建了一个Azure Cosmos DB(选择MongoDB作为语言),在通过Azure门户(网站)创建新文档时,它失败并说:

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

我试图通过网站创建以下文档:

{
    "wordpress_id": "test"
}

还有这个:

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

"wordpress_id" 是我在创建集合时定义的 "Shard key" (或分区键) . 它也是 Unique key .

这就是"Scale & Settings"标签中的see . 这是我在尝试创建文档时看到的error .

我错过了什么吗?

你知道为什么会这样吗?

1 回答

  • 2

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

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

    根据azure official document,我们可以知道我们可以使用 favorite tool,driver, or SDK 创建共享集合 .

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

    我用studio3t工具做了一个演示 . 我使用的Mongo Shell

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

    从studio3t运行Mongo Shell

    enter image description here

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

    enter image description here

相关问题