this query works for _id:2 but error for _id:1 since $addToSet will be error for non-array field. How can I make the linkedId become array if it null then add non-duplicate item on it using single operation?
Thank you on advance
Hi @steevej Thank you for the suggestion.
That’s what I do for now, I use 2 different update operations. But I wondering if there is a single update operation for that.
Hi @Edi_Krisnayana ,
Completely agree to what @steevej mentioned, but if still you need a single query for your use case then you have something like this -