Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Passaport-Local-Mongoose: How do i allow identical usernames

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;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!