I have a user.js model in my node app, and I'd like the username and a few other fields to be unique. In my model file I have properly declared the unique
type seen below:
// User Schema
const UserSchema = new Schema({
// PERSONAL USER INFO
username: {
type: String,
required: true,
index: true,
unique: true,
},
email: {
type: String,
required: true,
index: true,
unique: true
},
password: {
type: String,
required: true,
},
....
});
However, after restarting both my server and mongo session, I can still create users with the same Username and the same Email. I can do this from both the mongo shell and the front-end user registration page.
Is there a second part to this that I'm missing? I'm not for sure how to properly enforce the unique
type at this point. Thanks!