我有一个状态属性,我想应用日期过滤器只有当状态是待定,对于其他状态则不需要日期筛选器。
- 只返回添加到"$in"的状态。
- 如果状态为挂起,应用日期过滤器(日期小于当前时间)。
我确实喜欢这个,但是它不能正常工作。
filter = { $and: [ {
'package' : {$in: ids},
'status': {$in: ['pending', 'accepted', 'charged', 'captured']},
date
},
{
$and:[
{status : 'pending', date:{$lt:current_time}},
]
}
]
};
- 使用
$or
代替$and
,因为它将满足 其中一个条件 - 将
pending
状态从$in
状态中移除 $and
包含package
条件和$or
条件
filter = {
$and: [
{ package: { $in: ids } },
{
$or: [
{ status: { $in: ["accepted", "charged", "captured"] } },
{
status: "pending",
date: { $lt: current_time }
}
]
}
]
};
游乐场