[英]How to update data into mongodb using mongoose
尝试使用 mongoose 和 nodejs 更新 mongodb 中的值但不工作。我不知道该怎么做。 如果有人知道,请帮助我找到解决方案。
数据.controller.js:
module.exports.updateData = (req, res, next) => {
var uproducts = new updateProduct({
product_name: collectionDataJSON.product_name
});
updateProduct.updateOne({ p_id: thispid }, uproducts, function(err, raw) {
if (err) {
res.send(err);
}
res.send(raw);
});
}
更新方法不需要传递一个 mongoose object ,只需要传递一个普通的 object
像这样的东西
module.exports.updateData = (req, res, next) => {
var uproducts = { // a normal object
product_name: collectionDataJSON.product_name
};
updateProduct.updateOne(
{ p_id: thispid }, // filter part
{ $set: uproducts }, // update part
function (err, raw) { // call back
if (err) {
res.send(err);
}
res.send(raw);
}
);
}
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.