mongoose upsert add to array code example
Example 1: add items to a list in a document monoose
const {name , id} = req.body
Category.update(
{_id: id},
{$push: {items: {"name": name}}},{new: true, upsert: true }).exec();
res.sendStatus(200)
Example 2: mongodb add to array if not exists
db.tags.update(
{name: 'sport'},
{$addToSet: { videoIDs: "34f54e34c" } }
);