steevej
(Steeve Juneau)
4
I think so too. So I assumed it was a simple cut-n-paste issue since it was shared with the appropriate syntax in the first post linked by the author. It is a good thing you mentioned it as some readers might not have seen it.
Agree. It is a workaround and like most workaround it is only applicable for the bad situation you try to “work around”.
In this case, I understood that the author really wanted to do a $set on 1 element and a $push in the same array. And this cannot be done with a single update since you get a write exception as seen in this playground.
But this use-case occurs quite often. For example, in a tasks array, you would want to set the end_date of the current task and push a new task in the array.