我正在尝试用两个'或'来编写风帆水线查询。这两个条款都必须是真的,但它似乎不起作用。这是我尝试过的查询,但只有在其中一个或者'条款符合其标准,我只是在“和/或”时才会返回。条款'标准得到满足,而不是一个。这是一个错误还是有其他方法可以做到这一点?
Employee.find()
.where({
or: [
{locationId: employee.currentLocation.id},
{facilityId: employee.facilityId, userName:employee.userName,accountOwner: true}
]})
.where({
or:[
{employeeId: { startsWith: params.search.value }},
{fullName: { startsWith: params.search.value }},
{street: { startsWith: params.search.value }},
{emailAddress: { startsWith: params.search.value }},
{employeeType: { startsWith: params.search.value }},
{status: { startsWith: params.search.value }}
]});
答案 0 :(得分:0)
如果您正在使用mongo适配器,则可以将AND两个OR语句一起执行以下操作:
Employee.find().where({
$and: [{
or: [{
locationId: employee.currentLocation.id
}, {
facilityId: employee.facilityId,
userName: employee.userName,
accountOwner: true,
}],
}, {
or:[{
employeeId: { startsWith: params.search.value }
}, {
fullName: { startsWith: params.search.value }
}, {
street: { startsWith: params.search.value }
}, {
emailAddress: { startsWith: params.search.value }
}, {
employeeType: { startsWith: params.search.value }
}, {
status: { startsWith: params.search.value }
}],
}],
});