Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb复合密钥重复密钥错误_Mongodb_Compound Key - Fatal编程技术网

mongodb复合密钥重复密钥错误

mongodb复合密钥重复密钥错误,mongodb,compound-key,Mongodb,Compound Key,我面临一个重复的密钥错误,但没有找到解决方案。我使用以下命令创建了一个复合键: db.test.createIndex({"a":1,"b":1,"date":1},{unique:true}) 然后我插入了一个文档: { "a": "test_a", "b": "test_b", "date": "20170710", "data": "testing" } { "a": "test_a", "

我面临一个重复的密钥错误,但没有找到解决方案。我使用以下命令创建了一个复合键:

   db.test.createIndex({"a":1,"b":1,"date":1},{unique:true})
然后我插入了一个文档:

   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170710",
      "data": "testing"
   }
   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170711",
      "data": "testing"
   }
直到这里一切都很好。现在,当我尝试插入以下文档时:

   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170710",
      "data": "testing"
   }
   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170711",
      "data": "testing"
   }

我得到E11000重复密钥错误集合。如果每个文档中的索引不同,为什么会发生这种情况?谢谢

这是否返回任何内容:
db.test.find({“a”:“test_a”,“b”:“test_b”,“date”:“20170711”})测试集合上是否有其他唯一索引?您是否可以包含实际的重复键错误消息(应该包含索引和重复键的详细信息)?如果您的设置与当前描述的完全相同,则这两个文档具有不同的键。@Stennie我简化了示例,只是为了不发布我在数据库中使用的真实数据,是的,我在集合中还有其他唯一索引。以下是我尝试插入带有新复合键的新数据时报告的错误:“errmsg”:“E11000重复键错误集合:statistics.impressions\u分布索引:client\u id\u 1\u data\u 1\u session\u name\u 1 dup key:{:\“client\u 1\”,:null,:\“client\u 1\u 20170710\u 20170716\”}重复键错误消息包括索引名和冲突键的值,因此您可以使用这些来查找现有文档。复合索引中缺少的字段将是,因此看起来您的现有文档缺少索引中的第二个字段(
data
),并且正在尝试插入也缺少该字段的新文档。索引中的
数据
可能是
日期
的输入错误,还是这实际上是预期的字段?@Stennie,我发现了错误,愚蠢的我,我错误地写了
日期
,而不是
数据
。谢谢