Model.findById(req.body.myid, function (err, results) {
var doc = new Model(results);
doc._id = mongoose.Types.ObjectId();
doc.serial = req.body.serial;
doc.remarks = req.body.remarks;
doc.save(function(err) {
if(err){
res.json({ success: false });
}else {
res.json({ success: true });
}
});
});
如何创建文档副本并使用mongoosejs保存?
答案 0 :(得分:0)
还需要将isNew设置为true
doc._id = mongoose.Types.ObjectId();
doc.serial = req.body.serial;
doc.remarks = req.body.remarks;
doc.isNew = true;