如何将数据放入mongo db中,我从前端,节点+ expressjs接收?
这是我的模特:
module.exports = mongoose.model('MyData', { reportData: [{ _id: String, date: String, description: String, status: { type: String, default: 'new' } }], files: [{ originalname: String, filename: String, path: String, }], author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } })
这是put方法:
app.put('/upload/:id', bodyParser, async (req,res) => {
var author = req.params.id;
var report = (await MyData.find({author})).map(function(p){ return p.reportData; }).reduce(function(a, b){ return a.concat(b); }).find(x => x._id == req.body.reportId);
report.status = req.body.event
report.save(function(err, result){
res.json(result);
});
console.log(report.status)
});
目前上面的代码返回正确状态的正确对象,但不要将其保存到数据库。