1

Title says it all. Below is a schema property definition that I thought would work, but doesn't do the job. I figured required: true on the type object should work?

  users: {
    type: [
        {
          type: Schema.Types.ObjectId,
          ref: 'User',
          required: true
        }
    ],
    default: []
  }

the following query allows a null value to be added to the array:

MyModel.findByIdAndUpdate(id, {$addToSet: {users: ['']}})

1 Answer 1

1

aaaaaaaand, of course as soon as I post to SO, i find the answer for myself. need to set option runValidators: true on update...

This is the real reason I post to SO, its like always carrying an umbrella, its guaranteed not to rain.

Sign up to request clarification or add additional context in comments.

Comments

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.