Useful Queries

Select Many, Update Many w/ Childs

The problem with MongoDB is that if you do a forEach over a find, the object that you can use when you iterate is not modifiable.

let newStatus = 'canceled'; 
 
db.Object.find({
    "id": {
        "$in": [
            ObjectId("1"),
            ObjectId("2"),
            ObjectId("3"),
        ]
    }
}).forEach(object => {
    db.Child.updateMany({"object.$id": object.id}, {"$set": {
        "status": newStatus,
    }});
​    db.Object.updateOne({"id": object.id}, {"$set": {
        "status": newStatus,
    }});
});