Help achieving a specific update

Hi all, trying to figure out how to achieve an atomic update using either update aggregation or standard update.

Basic representation of my data is like this

{
  "subDocs": [
    {
      "someAmount": 10,
      "status": true,
    },
    {
      "someAmount": 10,
      "status": false,
    }
  ],
  "someTotal": 10,
} 

I want to, in the same transaction, conditionally update items in the array, and conditionally add values from the array and set “someTotal” to the value.

I can do both of these things independently, the former via a regular update document, and the latter via an aggregation. Can’t seem to figure out how to do the former in an aggregation update and I don’t think I can do the latter in a regular update doc as I don’t think I have access to the documents values in the update doc.

It would help if you provide a real source document, a real update with its real result.

Right now you have 2 objects with someAmount all being 10 and someTotal also being 10. We really don’t know how someAmount should be reflected in someTotal.

And before you publish documents, please read Formatting code and log snippets in posts

This is something to try

// starting collection
mongosh> c.find()
{ _id: 1,
  subDocs: 
   [ { someAmount: 10, status: true },
     { someAmount: 10, status: false } ],
  someTotal: 10 }
mongosh> amount = 7
mongosh> c.updateOne( { _id:1 } ,
  { "$inc" : { "someTotal" : amount } ,
    "$push" : { "subDocs" : { "someAmount" : amount } }
  }
)
// with the result
mongosh> c.find()
{ _id: 1,
  subDocs: 
   [ { someAmount: 10, status: true },
     { someAmount: 10, status: false },
     { someAmount: 7 } ],
  someTotal: 17 }