Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Strange behavior of display different error message for signup if username/email already exists on Mongo 3.0/3.2 #1245

Closed
@QiyuLi

Description

@QiyuLi

@trendzetter @ilanbiala

I'm reading Mongoose doc. I did not find any info about configuring err msg for unique.
I'm running Ubuntu 14.04 with MongoDB 3.2.3. Nodejs is v4.3.2

I attached a screenshot. This is not good to display such a detailed error.
image
image

I tested with clean enviroment in vagrant. The only difference is: MongoDB 3.0.9 and 3.2.3.
I wonder where does the sentence "Email already exists" or '11000 duplicate key error collection: mean-test.users index: username already exists' to be 'Username already exists' come from?

I enabled the debug mode of mongoose. I tested with both Mongo 3.0 and 3.2.
The query generated by mongoose is the same (execept salt).
Then I execute the insert query manually in Mongo 3.0 and 3.2.
The output is also the same.

Mongo 3.0
Mongoose: users.insert({ salt: 'RphFQ5BmRcgAxoa9vAaCTQ==', displayName: 'Test User', provider: 'local', username: 'testuser', _id: ObjectId("56d767da3ccc59b408859f90"), created: new Date("Wed, 02 Mar 2016 22:23:22 GMT"), roles: [ 'user' ], profileImageURL: 'modules/users/client/img/profile/default.png', password: '9WsKha9q20AQdR6jYfBIv9LSYg5Qsfa+MTLFka0KmazFcGKh9VKVxFm1ft3S2AjqIVJorN4ihEz1nOoH6U22UA==', email: '[email protected]', lastName: 'User', firstName: 'Test', __v: 0 })
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error index: mean-dev.users.$username_1 dup key: { : "testuser" }"
}
})

Mongo 3.2
Mongoose: users.insert({ salt: 'd4SiQVR3xDk0rqHQ3dajNw==', displayName: 'Test User', provider: 'local', username: 'testuser', _id: ObjectId("56d7684543b5be880b8aedd7"), created: new Date("Wed, 02 Mar 2016 22:25:09 GMT"), roles: [ 'user' ], profileImageURL: 'modules/users/client/img/profile/default.png', password: 'hsKel5Gew/IVqoo8oynaOFayV35sKP07xbcApvVosAhILPg99l0ccv74+mu7k14+ph2LJpxQ5ntPsDBTMtYhag==', email: '[email protected]', lastName: 'User', firstName: 'Test', __v: 0 })
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error index: mean-dev.users.$username_1 dup key: { : "testuser" }"
}
})

I think mongodb does not change error reply. I wonder whether mongoose or other plugin changes the err msg behavior.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions