0

I build simple user register app. My User model this:

const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose')
const { Schema } = mongoose;

const userSchema = new Schema({
  email: {
    type: String,
  },
  phoneNumber: {
    type: String
  },
  firstName: {
    type: String
  },
  lastName: {
    type: String
  },
  password: {
    type: String
  },
  googleId: {
    type: String
  },
  facebookId: {
    type: String
  },
  avatar: {
    type: String
  },
  role: {
    type: String,
    default: 'Member',
    enum: ['Admin', 'Member', 'Merchant']
  },
  resetPasswordToken: { type: String },
  resetPasswordExpires: { type: Date },
},{
  timestamps: true
}));

userSchema.plugin(passportLocalMongoose, {usernameField: 'email', usernameQueryFields:['email']});

module.exports = mongoose.model('User', userSchema);

When send data first time was success but second time I get this error:

{
    "index": 0,
    "code": 11000,
    "keyPattern": {
        "username": 1
    },
    "keyValue": {
        "username": null
    }
}

How to fix it or find error?
Thanks

  • Does this answer your question? [E11000 duplicate key error index in mongodb mongoose](https://stackoverflow.com/questions/24430220/e11000-duplicate-key-error-index-in-mongodb-mongoose) – SuleymanSah Sep 06 '22 at 14:18
  • I didn't use username. but it is give me this error. Error like this but this error give me passport local mongoose. – Jorakuly Atamuradow Sep 06 '22 at 15:31

0 Answers0