I have a data model which looks like this
{
_id: 1
some_property: some_value
items: [
{
item_id: item1
item_properties: [
{
key1: val1,
key2: val2
}]
}]
}
When I get a new item with item_id=itemX
, I would like to check if an item with this item_id is in the items array. If it's not present, then insert it. If it is present, i would like to append the item_properties to the existing item_properties.
I tried using $addToSet
, but this considers the entire item and not the item_id itself. So the result was 2 items with the same item_id.
Any idea how i can achieve this atomically?
Thanks, Aliza