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

aggregate([
                {
                    "$lookup": {
                        "from": UserModel.collection.name,
                        "localField": "threat.lastModifiedBy",
                        "foreignField": "username",
                        "as": "inventory_docs"
                      }
                },
                {"$project":{
                    inventory_docs:1,
                    project:1,
                }},
                {
                    $set: {
                      "threat.$.reviewedBy": {
                        $arrayElemAt: [
                          "$inventory_docs._id",
                          0
                        ]
                      }
                    }
                  }
            ])

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.