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
Post a Comment