Update/upsert array within array using update aggregate?

I have a collection containing documents as such:

    "list": [
        "item": 1,
        "sub_list": [ 11 ]
        "item": 2,
        "sub_list": [13, 43]

How do I add a number to the sub_list given category & item? and if it doesn’t exist then upsert and create

  "category": "A", // "B" will create/upsert new document
  "list.item": 1 // 2 will add new obj to list
  upsert: true

Hello @MRM,

You cannot directly update/upsert an array within an array using a normal update query in MongoDB. You will need to use the update with an aggregation pipeline to achieve this complex update/upsert operation.

For reference, refer to this question,