When updating values dynamically, I often need to set or unset them. However, there are times when I only need to do one or the other. Here is my current approach:
Collection.update(
{ _id: id },
{
$set: data,
$unset: remove
},
function (error) {
console.warn(error);
}
);
This method works fine when both data
and remove
are defined. But if there is nothing to be removed, setting remove = {}
leads to a 409 error because remove
is empty.
How can I enhance the update process to address this issue?