it might be a noob question :-), but I don’t understand why I get my Plate object with changed values before I change it. Have anyone an idea? See my code snippet below:
var currentPlate = Plate.findOne({_id: currentPlateId}); //Object with {b1: false, b2: false, b3: false, b4: false, ...}
delete currentPlate._id;
console.log(currentPlate); //Why I get here the object with {b1: true, b2: true, b3: true, b4: true, ...}
for (var i = 1; i < 5; i++) {
var name = 'b' + i;
currentPlate[name] = true;
}
No my code snippet is complete. Before writing my issue here, I tried your example as well and it works like in your example. But if I get the Object from Mongodb it don’t work. Look on the attached screenshot:
That’s expected behavior. Javascript stores all non-primitive variables by reference. currentPlate references the same thing. When the console object is opened, it loads the current currentPlate which is now all true.