jaredhanson / passport-facebook

Facebook authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-facebook/?utm_source=github&utm_medium=referral&utm_campaign=passport-facebook&utm_content=about
MIT License
1.29k stars 446 forks source link

E11000 duplicate key error collection #289

Open dinesh6383 opened 1 year ago

dinesh6383 commented 1 year ago

I couldn't be able to register through facebook once after i registered and logout out from google auth. Kindly someone help me to solve this issue!. ///////////////////////////////////////////////////////////////////////////////////////////////////////// MongoServerError: E11000 duplicate key error collection: usersDB.users index: username_1 dup key: { username: null } at E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\operations\insert.js:53:33 at E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\cmap\connection_pool.js:308:25 at E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\sdam\server.js:213:17 at handleOperationResult (E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\sdam\server.js:329:20) at Connection.onMessage (E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\cmap\connection.js:219:9) at MessageStream. (E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\cmap\connection.js:60:60) at MessageStream.emit (node:events:527:28) at processIncomingData (E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\cmap\message_stream.js:132:20) at MessageStream._write (E:\backend-development\Secrets - Starting Code\node_modules\mongodb\lib\cmap\message_stream.js:33:9) at writeOrBuffer (node:internal/streams/writable:389:12) { index: 0, code: 11000, keyPattern: { username: 1 }, keyValue: { username: null }, [Symbol(errorLabels)]: Set(0) {} } /////////////////////////////////////////////////////////////////////////////////////////////////////////

mdahtotul commented 1 year ago

This is a monogo error. In your mongoose schema you maybe defined as username {type string, unique:true}. So when you are storing data in DB, only one null value for username will store. After that if username field has null value duplicate error will throw. Change username field as below

username: { type: String, index: true, unique: true, sparse: true, }

After changing the schema. Drop that specific collection. And try again. No username field will only take multiple null values.

Mohitraut07 commented 1 month ago

It still doesn't work...