'mongoose $push, $each, results in duplicates

Syntax:

{
  $push: { keywords: { $each: req.body.keywords }}
},

Data:

req.body.keywords

contents:

"keywords": ["windows","cybersecurity","passwords","chrome","security"]

Action:

findOneAndUpdate({}).clone();

Without the clone() at the end, just errors happen.

PROBLEM: Duplicate keywords.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source