MongoServerError:E11000 duplicate key error....
mongodb在插入数据时出现id重复错误
解决
在设定的数据模型里面新加一个id
const mongoose = require('mongoose')
const UserSchema = new mongoose.Schema({
id: {
type: Number,
default: new Date()
},
name: {
type: String,
required: [true, "请添加名字"],
}
......
});
module.exports = mongoose.model('User', UserSchema)