A bunch of similar questions answered before but none of them seem to fix my problem. No problem in adding the first user. However, the username doesn't display the records and gives error on adding the second user.
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const userSchema = new Schema(
{
username: {
type: String,
unique: true,
required: true,
minlength: 3,
},
gender: String,
age: Number
},
{
timestamps: true
}
);
const User = mongoose.model('user', userSchema);
module.exports = User;
user
document that you are saving has a not nullusername
. I think during the first and second time username is passed as null to the database. – Interpolaterequired: true
, if it is saving without a username – Piton