Below is an example of how to update the value in the array of objects more dynamically.
Person.findOneAndUpdate({_id: id}, { "$set": {[`items.$[outer].${propertyName}`]: value} },{ "arrayFilters": [{ "outer.id": itemId }]},function(err, response) { ...})
Note that by doing it that way, you would be able to update even deeper levels of the nested array by adding additional arrayFilters
like so:
"$set": {[`items.$[outer].innerItems.$[inner].${propertyName}`]: value} "arrayFilters":[{ "outer.id": itemId },{ "inner.id": innerItemId }]
I hope it helps. Good luck!