In the case that the variable author
is defined, an update is made to the mongoDB document to add a new object { assignTo: author }
. This will either create or update the existing document.
If author
is empty, I need to remove the assignTo
field from the document. What is the best way to accomplish this?
if (author) {
Collection.update(
{ _id: id },
{ $set: { assignTo: author } }
);
}
else {
// remove the object from the collection
}