Stored within a mongoDB document is the following data:
{
_id: "123"
order: 1
parent: "Dueqmd64nTxM3u9Cm"
type: "article"
unit: "kg"
}
Prior to updating the document, all saved data undergoes calculations and validation. Therefore, the complete object is used for updating rather than just data = { order: 2 }
:
var data = {
order: 2
parent: "Dueqmd64nTxM3u9Cm"
type: "article"
unit: "kg"
}
Collection.update(
{ _id: 123 },
{ $set: data }
);
This method works as intended.
However, if attempting to remove certain values from the document, it does not work as expected:
var data = {
order: 2
parent: "Dueqmd64nTxM3u9Cm"
type: "article"
unit: undefined
}
Collection.update(
{ _id: 123 },
{ $set: data }
);
The expectation was for the unit
field to be removed, but this does not occur...