我正在通过 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/