async add(data) {
return new Promise(async (resolve, reject) => {
let model = new Model();
model.name = data.name;
try {
await mainCategory.save();
resolve(true);
} catch (err) {
reject(err);
}
});
}
我已经编写了类似thise的代码,以使用mongoose将数据保存到mongodb中,这会引发这样的错误
{
"level": "error"
}
此错误是从捕获得到的。
这是我的模型架构
let category = new Schema({
name: {
type: String,
unique: true,
required: true
},
imageUrl: {
imageUrl
},
subCategories: [{
type: Schema.Types.ObjectId,
ref: 'SubCategory'
}]
});
答案 0 :(得分:0)
async add(data){
model.name = data.name;
let model = new Model();
model.save()
.then(callback => {
console.log(callback)
})
.catch(err => console.error(err))
}
Try this