我使用MongoDB Node.js驱动程序。我的查询如下所示:
var query = {
$and: [{
"custom_date": {
"$gte": minDateValue,
"$lt": maxDateValue
}
}, {"doc_name": {"$in": file_type}}, {"sample_type": {"$in": sample_type}}, {"mission": {"$in": mission}}, {"snow_thickness": {"$in": snow_thickness}},{
"depth_m": {
"$gte": minDepthOut,
"$lt": maxDepthOut
// Or equal to "NA"
}
}]
};
一切正常,但我想在字段depth_m中添加$ in或$ or,因此查询的这一部分将为“ $ gte”:minDepthOut,“ $ lt”:maxDepthOut或等于“ NA” “例如。
我的意思是depth_m必须在指定范围内或等于“ NA”
感谢您的帮助
答案 0 :(得分:1)
您可以使用$or
查询运算符
{
"$and": [
{ "custom_date": { "$gte": minDateValue, "$lt": maxDateValue }},
{ "doc_name": { "$in": file_type } },
{ "sample_type": { "$in": sample_type } },
{ "mission": { "$in": mission } },
{ "snow_thickness": { "$in": snow_thickness } },
{ "$or": [
{ "depth_m": {
"$gte": minDepthOut,
"$lt": maxDepthOut
}},
{ "depth_m": "NA" }
}]
]
}