Код: Выделить всё
E11000 duplicate key error collection: test.users index: username_1 dup key: { username: null }Я проверил файл models/User.js десять раз. Я использую только имя, адрес электронной почты, роль и googleId. Я даже не отправляю имя пользователя из своего интерфейса.
Код: Выделить всё
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
role: { type: String, enum: ["founder", "mentor"], required: true },
googleId: { type: String, required: true },
//other imp fields
}, { timestamps: true });
module.exports = mongoose.model("User", userSchema);
Код: Выделить всё
// This fails on user.save() for the second person who tries to sign up
const user = new User({
name: req.body.name,
email: req.body.email,
role: req.body.role,
googleId: req.body.uid
profilePicture: req.body.picture,
bio:"",
});
await user.save();
Код: Выделить всё
MongoServerError: E11000 duplicate key error collection: test.users index: username_1 dup key: { username: null }
at InsertOneOperation.execute (/home/samiii/Documents/prabal_project/backend/node_modules/mongodb/lib/operations/insert.js:51:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async tryOperation (/home/samiii/Documents/prabal_project/backend/node_modules/mongodb/lib/operations/execute_operation.js:207:20)
at async executeOperation (/home/samiii/Documents/prabal_project/backend/node_modules/mongodb/lib/operations/execute_operation.js:75:16)
at async Collection.insertOne (/home/samiii/Documents/prabal_project/backend/node_modules/mongodb/lib/collection.js:157:16) {
errorLabelSet: Set(0) {},
errorResponse: {
index: 0,
code: 11000,
errmsg: 'E11000 duplicate key error collection: test.users index: username_1 dup key: { username: null }',
keyPattern: { username: 1 },
keyValue: { username: null }
},
index: 0,
code: 11000,
keyPattern: { username: 1 },
keyValue: { username: null }
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... field-i-ha
Мобильная версия