我通过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
任何帮助都将不胜感激。
答案 0 :(得分:4)
将{query}替换为查询。
var cursor = db.collection("tbl_Patients").find(query);