javascript - How to query for objects stored in an array in a mongoDB -


i have following nested object stored in mongodb:

var appointment = new schema ({      students: [{user1:string,user2:string, _id: false}], }); 

i want query appointments studentname stored in array students either in user1 or user2. have no idea how achieve that? if array use:

    appointment.find({         students: {$in: [studentname]}     }, function(err, appointmentsdb) {         //     }); 

you can use $or operator , dot notation this:

appointment.find({ $or: [     { 'students.user1': studentname },     { 'students.user2': studentname } ]}, callback); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -