在mongoose变量字符串数组中查询$

时间:2015-10-05 06:57:15

标签: node.js mongodb express mongoose

我有以下型号:

var MessageSchema = new Schema({
    msgID: String,
    patientList: [String],
    created_at: Date,
    updated_at: Date
});

patientList始终是可变的。

我尝试创建一个Mongoose查询,该查询可以找到给定patientID属于给定消息的patientList的所有记录。这就是我正在尝试的,但我一直在空记录。

    var patientID   = req.params.patientID;
    var query = Message.find({});

    if(patientID){
        console.log(patientID);
        query = query.where(patientID).in('patientList');
    }

我所看到的所有其他问题都试图在具有已知值的数组中进行查询。就我而言,patientList可以有任意数量的patientID。

有什么想法吗?

现在我只是得到以下输出:

{
"name": "MongoError"
}

1 个答案:

答案 0 :(得分:0)

阿。找到我的答案......显然这有效:

query = query.where('patientList').equals(patientID);