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