Update elements in array

Hi, I want to update three fields namely primary_ids, secondary_ids and wildcard_ids. All are of type array of int. I am doing this using $addToSet operator. In case, If any of the field does not exist or is null, then the query is returning error.

Is there a way to check which field is null before $addToSet or any other method to implement this.

Thank you!

Hi @Sahildeep_Kaur,

Could you provide the following information:

  • What you have attempted so far using $addToSet
  • 4-5 sample documents
  • Expected output based off the 4-5 sample documents
  • The MongoDB version in use


Hey, Thank you but I have done it.

1 Like