when using arrayFilters, it is not possible to determine if the full query (including arrayFilters) matched anything.
For example, given the document:
Now run an update:
So far so good, now let's run another update:
Has no effect. The upsert: true has no effect because it only applies to the match predicate in the first parameter. My request is not to change the behavior here, I'm just noting for discussion.
Running this query in production, it would be impossible to know if the update just simply didn't have nModified > 0 because the arrayFilter didn't match anything, or because the count value was already 1 and so no data modification occurred.
I can see that the value for nMatched needs to be 1 because it is applied to the document level, not the subdocument level (as arrayFilters can be used across multiple sub documents within a single document, it would be difficult to assert the meaning of this value if it took that into consideration).
I'm not sure what the best solution is, but I believe it is a shortcoming.
Perhaps there is additional information returned in writeResult.
Perhaps the update positional operator needs to be expanded so that the arrays deeper than 1 level can be updated. (I think this is a bad idea for other reasons).
I like arrayFilters, and it is very useful and extendible, but it is hard to work with when "upsert" functionality is desired.
Thank you for your consideration.