I'm using Passport Local Mongoose to create a user on my database. My goal is to allow users with the same username to register into my app. On my research, i found that if i pass an object as option on my Schema.plugin with 'usernameUnique: false', i would allowed users to register with the same username. The only problem is when a try it to make a register, i get an "UserExistsError" on my console.
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const passportLocalMongoose = require('passport-local-mongoose');
const UserSchema = new Schema({
email: {
type: String,
required: true,
},
username: {
type: String,
required: true,
unique: false
},
});
const options = {
usernameUnique: false,
}
UserSchema.plugin(passportLocalMongoose, options);
const User = mongoose.model('User', UserSchema);
module.exports = User;