How to update a single field in an array of objects using aggregation

What I need to do is to search the whole collection and check the threats array of objects

In that array currently there is a “lastModifiedBy” field that contains a username

I need to get the userName and search the user db and instead set the user Id on that field

                    "$lookup": {
                        "localField": "threat.lastModifiedBy",
                        "foreignField": "username",
                        "as": "inventory_docs"
                    $set: {
                      "threat.$.reviewedBy": {
                        $arrayElemAt: [

I know that in a normal update you can use the $. to update an array of object but that does not seem to work in aggregation

Take a look at $map. It is used to modify array.