I'm looking to $push something into a nested array, of which the parent array matches a simple property condition:
Here's how my document looks:
{
name: "Foo",
boardBucket: {
currentBoardId: 1234,
items: [ <- looking to push into `boardItems` of an `item` in this Array
{
boardId: 1234, <- that has `boardId: 1234`
boardItems: [ "barItem", "deyItem" ] <- Final Array I want to push to
}
]
}
}
So I'd like to push "fooItem" in boardItems of item that has boardId: 1234
Option 1: I can use dot notation and access by index
I can certainly do a $push by using dot.notation which uses the index of the item like so:
this.update({ '$push': {"boardBucket.items.0.boardItems": "fooItem" } });
But what if I don't know the index?
How can I push into boardItems of item with boardId: 1234 without using the indices (using the boardId instead)?
Note:
- I'm using mongoose as the db driver
- I'd like to avoid using mongoose's
save()cause it tends to be buggy + it seems to keep a copy of the object locally which i'd like to avoid - Just direct
update()mongo queries are what I'm after - I'd certainly like to avoid any type of whole-document fetching to perform this update as my documents are huge in size