问题描述
根据此高度不完整列表 http://www.mongodb.org /about/contributors/error-codes/它们都与重复键有关.但是我无法收到11001错误.以下所有内容均引发11000错误:
According to this HIGHLY incomplete list http://www.mongodb.org/about/contributors/error-codes/ they're both related to duplicate keys. But I was not able to get a 11001 error. All of the following threw a 11000 error:
- 使用已经存在的
_id
插入文档 - 插入具有重复字段的文档,其中这些字段具有复合唯一索引
- 使用所述复合唯一索引更新文档
- inserting a document with an
_id
that already existed - inserting a document with duplicate fields where the fields had a compound unique index
- updating a document with said compound unique index
因此,这完全与链接页面相反,链接页面上的11000表示_id
,而11001表示更新(而不是插入).
So this goes completely against the linked page, which says 11000 is for _id
and 11001 would occur on updates (not inserts).
所以我的问题是:什么时候发生11001?
So my question is: When does 11001 occur?
推荐答案
代码11001
在GitHub上的2.5/2.6分支中不存在,因此,如果您尝试使用2.5版本,则无法创建它.我确实看过代码,但是找不到任何直接显示11001
代码的路径.
The code 11001
does not exist in the 2.5/2.6 branch on GitHub, so if you're trying a 2.5 version than you can't create it. I did have a look at the code, but I can't find any path that shows the 11001
code either directly.
以下几行将显示代码11001
:
db.so.drop();
db.so.insert( { foo: 5 } );
db.so.ensureIndex( { foo: 1 }, { unique: true } );
db.so.insert( { foo: 6 } );
预期的11000
:
db.so.insert( { foo: 5 } );
E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 }
现在到达11001
:
db.so.insert( { foo: 6 } );
db.so.update( { foo: 6 }, { $set: { foo: 5 } } );
E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 }
仍然是原始的11000
,但是:
db.getPrevError();
{
"err" : "E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 }",
"code" : 11001,
"n" : 0,
"nPrev" : 1,
"ok" : 1
}
原始文本错误消息显示E11000
是一个错误: https://jira. mongodb.org/browse/SERVER-5978
That the original textual error message shows E11000
is a bug: https://jira.mongodb.org/browse/SERVER-5978
这篇关于错误代码11000和11001之间的MongoDB差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!