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
that already existedSo this goes completely against the linked page, which says 11000 is for _id
and 11001 would occur on updates (not inserts).
So my question is: When does 11001 occur?
The error E11000 duplicate key error ... { person_name: 'Carl-Fredrik Linder' } is saying that the aggregation query is trying to create a document with person_name: 'Carl-Fredrik Linder' more than once - that is violating the unique index constraint on the person_name in the persons collection.
The Current Procedural Terminology (CPT®) code 11000 as maintained by American Medical Association, is a medical procedural code under the range - Debridement Procedures on the Skin.
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.
The following few lines will show code 11001
:
db.so.drop(); db.so.insert( { foo: 5 } ); db.so.ensureIndex( { foo: 1 }, { unique: true } ); db.so.insert( { foo: 6 } );
The expected 11000
:
db.so.insert( { foo: 5 } ); E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 }
And now to reach the 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 }
Still the original 11000
, but:
db.getPrevError(); { "err" : "E11000 duplicate key error index: test.so.$foo_1 dup key: { : 5.0 }", "code" : 11001, "n" : 0, "nPrev" : 1, "ok" : 1 }
That the original textual error message shows E11000
is a bug: https://jira.mongodb.org/browse/SERVER-5978
Mongo has an ErrorCategory
enum which creates a DUPLICATE_KEY_ERROR
for the following error codes:
private static final List<Integer> DUPLICATE_KEY_ERROR_CODES = Arrays.asList(11000, 11001, 12582);
The above is from mongodb java driver 3.6.4.
So both refer to duplicate keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With