My document structure includes the following:
{
_id: ...,
name: ...,
keywords: {
group_a: [1, 2, 5],
group_b: [4, 7, 6]
}
}
I've figured out how to add elements to one of the elements in the keywords
object like this:
db.coll.update({_id: ...}, {
$addToSet: {
'keywords.group_a': {
$each: [9, 12, 17]
}
}
})
But is there a way to add the same set of elements to both group_a
and group_b
? Perhaps something similar to
db.coll.update({_id: ...}, {
$addToSet: {
['keywords.group_a', 'keywords.group_b']: {
$each: [9, 12, 17]
}
}
})
Even though the above code isn't valid, I am looking for a solution where I can specify the names of the groups in advance and add the elements to all of them simultaneously.