マングースの文書で述べられているように、これは私たちがこれを行う方法です:
db.collection.updateMany(condition, update, options, callback function)
したがって、これはドキュメントに基づく例です。
// creating arguments
let conditions = {};
let update = {
$set : {
title : req.body.title,
description : req.body.description,
markdown : req.body.markdown
}
};
let options = { multi: true, upsert: true };
// update_many :)
YourCollection.updateMany(
conditions, update, options,(err, doc) => {
console.log(req.body);
if(!err) {
res.redirect('/articles');
}
else {
if(err.name == "ValidationError"){
handleValidationError(err , req.body);
res.redirect('/new-post');
}else {
res.redirect('/');
}
}
});
これは私にとってはうまくいきました、私はそれが役立つことを願っています:)