Problem description:
MongoError: E11000 duplicate key error collection: test.elementusers index: username_1 dup key: { username: "admin" }
at Function.create (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/error.js:44:12)
at toError (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/utils.js:150:22)
at coll.s.topology.insert (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/operations/common_functions.js:266:39)
at handler (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/sdam/topology.js:1000:24)
at wireProtocol.(anonymous function) (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/sdam/server.js:457:5)
at /Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/connection/pool.js:408:18
at process._tickCallback (internal/process/next_tick.js:61:11)
driver: true,
name: 'MongoError',
index: 0,
code: 11000,
keyPattern: { username: 1 },
keyValue: { username: 'admin' },
errmsg:
'E11000 duplicate key error collection: test.elementusers index: username_1 dup key: { username: "admin" }',
[Symbol(mongoErrorContextSymbol)]: {}
MongoError: E11000 duplicate key error collection: test.elementusers index: username_1 dup key: {username: “admin”}
at Function. Create
driver: true,
name: ‘MongoError’,
index: 0,
code: 11000,
keyPattern: {username: 1},
keyValue: {username: ‘admin’},
errmsg:
‘E11000 duplicate key error collection: Test.elementusers index: username_1 dup key: {username: “admin”}’,
[Symbol(mongoErrorContextSymbol)]: {}
The reason:
Because unique:true is set in the Schema, the registered user name must be unique.
We can make a corresponding judgment in ERR.
if(err.code == '11000'){
res.json({
msg:'This username has already been registered, please change your username',
success:false
})
}
Read More:
- E11000 duplicate key error collection in mongodb
- pymongo.errors.DuplicateKeyError: E11000 duplicate key error collection: anjuke.ershoufang index
- mysql Error Code: 1022. Can’t write; duplicate key in table `xxx`
- Solution of duplicate entry ‘value’ for key ‘field name’ in MySQL
- The solution of duplicate entry ‘for key’ primary ‘when inserting data in MySQL
- Duplicate entry ‘787192513’ for key ‘primary’
- Txt import MySQL: error 1062 (23000): duplicate entry ‘0’ for key ‘primary’
- Dbsql occurs when configuring SAP ATC during SCI check_DUPLICATE_KEY_ERROR
- Lambda set to map duplicate key error solution
- SSIS Error:Package Validation Error. SSIS Error Code DTS_E_OLEDBERROR. .Error code: 0x80040E37. An …
- Error: cannot find module ‘mongoose’
- Error 0210: stick key 28 is displayed when ThinkPad E40 is turned on
- MySql ERROR CODE:1215 Cannot add the foreign key constraint
- E: sub process / usr / bin / dpkg returned an error code (2) solution under Ubuntu
- SSIS Error Code DTS_E_OLEDB_EXCEL_NOT_SUPPORTED
- Use mujoco = = 0.5.7 to run the code and report error: invalid activation key
- E: Sub process / usr / bin / dpkg returned an error code (1) solution
- Syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
- Error in upload code of tortoisegit error:1407742E
- MySQL:Foreign key fails with error Error Code: 1452.