When using $push or $addToSet operator in mongoose, and the value I give (friend.id) is null or undefined, it will push a null element to the array.
dbUser.findByIdAndUpdate(
_id,
{
$addToSet: {
'friendsBlackList': friendB.id ,
'FriendsWhiteList': friendW.id ,
},
},
{ new: true, upsert: true }
});
How to avoid pushing a null element? Can it be controlled in the mongoose schema? Thank you for your suggestions.
friend.idbefore issuing the query?