1

I'm using Mongoose and have a schema like this:

var User = new mongoose.Schema({
    registrations:[{
        fieldA: String,
        fieldB: String,
    }]
});

var UserModel = mongoose.model('User', User);

I want to find all users that their registrations array does not contain objects with fieldA == 'specific value'.

1 Answer 1

6

Use the $ne operator and dot notation to do this:

UserModel.find({'registrations.fieldA': {$ne: 'specific value'}}, cb);

When used with an array field like this, $ne will only match docs where no array element contains the specific value.

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.