0

I'm adding elements into an array("users") by using the $addToSet, but sometimes the array is null. Already tried to check if is null, and if it is use the $push, but I'm getting a The field 'users' must be an array but is of type null in document. Any ideas? This is the code I'm using:

    if(!userIsAssociated(campaign,user)){
    collection.updateOne(
            Filters.eq("_id", new ObjectId(id)),
            Updates.push("users", user));
    }
4
  • Can you provide code for users array? Commented Sep 12, 2017 at 16:32
  • It's an array of strings. The problem is when user: null Commented Sep 12, 2017 at 16:56
  • correction: users:null Commented Sep 12, 2017 at 17:03
  • 2
    This will help. stackoverflow.com/questions/31770550/… Commented Sep 12, 2017 at 17:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.