0

I have the following nested object stored in my mongoDB:

var Appointment = new Schema ({

    students: [{user1:String,user2:String, _id: false}],
});

I now want to query my appointments for a studentName which is stored in the array students either in user1 or user2. But I have no idea how I could achieve that? If it is an array I would use:

    Appointment.find({
        students: {$in: [studentName]}
    }, function(err, appointmentsDb) {
        // do something
    });

1 Answer 1

2

You can use an $or operator and dot notation for this:

Appointment.find({ $or: [
    { 'students.user1': studentName },
    { 'students.user2': studentName }
]}, callback);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.