Articles → MONGODB → $Addtoset Operator In Mongodb
$Addtoset Operator In Mongodb
Purpose
Syntax
db.collection.update(
{ [query] },
{ $addToSet: { [field]: [value] } }
)
Example
db.mycollection.updateOne(
{ "_id": 1 },
{ $addToSet: { "interests": "sports" } }
)
Output