Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何查询mongoDB中数组中存储的对象_Javascript_Mongodb_Mongoose - Fatal编程技术网

Javascript 如何查询mongoDB中数组中存储的对象

Javascript 如何查询mongoDB中数组中存储的对象,javascript,mongodb,mongoose,Javascript,Mongodb,Mongoose,我的mongoDB中存储了以下嵌套对象: var Appointment = new Schema ({ students: [{user1:String,user2:String, _id: false}], }); 现在我想查询一个studentName的预约,该studentName存储在数组students user1或user2中。但我不知道我如何才能做到这一点? 如果它是一个数组,我将使用: Appointment.find({ students:

我的mongoDB中存储了以下嵌套对象:

var Appointment = new Schema ({

    students: [{user1:String,user2:String, _id: false}],
});
现在我想查询一个studentName的预约,该studentName存储在数组students user1或user2中。但我不知道我如何才能做到这一点? 如果它是一个数组,我将使用:

    Appointment.find({
        students: {$in: [studentName]}
    }, function(err, appointmentsDb) {
        // do something
    });
您可以为此使用运算符和点表示法:

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