javascript - 未知运营商 : $and in MongoDB

标签 javascript node.js mongodb

我正在通过 node.js 代码查询 mongodb。 我的mongo文档集合(Patients Collection)结构如下:+

Patient collection

{ 
    "_id" : ObjectId("59e5c28f37ce021e142e7ead"), 
    "MRN" : "00126389", 
    "Family_Name" : "Jones", 
    "First_Name" : "Lydia", 
    "Father_Name" : "Bob", 
    "Maiden_Name" : "", 
    "Mother_Name" : "n/a", 
    "Spouse_Name" : "", 
    "Address" : "", 
    "Telephone_Nbr" : "", 
    "Patient_Visit" : {
        "Department" : "ER", 
        "Hospital_Status" : "Active", 
        "Case_Nbr" : "17", 
        "Admission_Date" : "01/04/2011 12:00:00 AM", 
        "Admission_Time" : "14:02"

    }
}

我的查询执行代码如下所示:

mongoClient.connect(mongoConstr, function(err, db) {
    if (err) throw err;
    var query = {
        $and: [{
            "Patient_Visit.Department": "ER"
        }, {
            $or: [{
                "Patient_Visit.Hospital_Status": "Active Left"
            }, {
                "Patient_Visit.Hospital_Status": "Active"
            }]
        }]
    };
    var cursor = db.collection("tbl_Patients").find({
        query
    });
    cursor.forEach(function(doc) {
        console.log(JSON.stringify(doc));
    }, function(err) {
        db.close();
        throw (err);
    });
});

执行请求时出现以下错误:

MongoError: unknown operator: $and

如有任何帮助,我们将不胜感激。

最佳答案

用查询替换{query}。

var cursor = db.collection("tbl_Patients").find(query);

关于javascript - 未知运营商 : $and in MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46845304/

相关文章:

node.js - 当我尝试在 cPanel 上安装 Laravel 时出现 pngquant 错误

mongodb - 从 Haskell MongoDB 驱动程序中检索错误状态

javascript - 同一个源 iframe 的 Express.js : get req. body.datas

javascript - 如何通过ID从其他表中获取名称

javascript - 如何在 JSS 格式上编写多个 CSS 属性?

javascript - Express.js 静态 html 与 get

node.js - 是否可以用 C(不是 C++)编写 node.js 扩展?

mongodb - 如何连接mongodb和Informix服务器

mongodb - Cubism.js 与 mongodb 和实时数据

JavaScript 填充页面的其余部分不起作用