Thanks to the help received in my previous question (UpdateMany mongodb documents with value from document), I have learned about incrementing using updateMany. I wrote the
Was just curious to know if this is better.
ageAllCameraPriorities = async (req, res) => {
await Camera.updateMany(
{ enabled: true },
{ $inc: { processingPriority: 1 } }
).then((dbResp) => {
if (!dbResp.n) {
return res
.status(404)
.json({ success: false, error: `No enabled cameras found to age` })
}
return res.status(200).json({ success: true, data: dbResp })
}).catch(err =>
console.log(err);
return res.status(400).json({ success: false, error: "Status 400, unable to age camera priorities" + err });)
}