Why is my Mongodb aggregation pipeline updateOne() working in compass, but not working in my node driver

An aggregation does not update the original document and since you are calling updateOne, I assume that you want to update the original document. So whatever what you end up doing in your aggregation with limit:1 or not, your original document will not be updated.

I was able to update all wieghts.$.spotsAvailable by using the arrayFilters:

{ "el2" : { "userId" : "empty" , "name" : "empty" } }

I still do not know how to set up a filter that test only one of the field of a sub-object.

I still do not know how to limit the update to a single element using arrayFilters.

The only way I could make work what I think you want to achieve (assign an available spot to a participant) is by modifying your model to

and update with

2 Likes