user table associated with consumption table
want to query the conditions of users who have not consumed for 3 months
match2
by the way, how to optimize the following conditions?
match0 = {"$match": {"regDate": {"$gte": day_30, "$lt": today}}}
match1 = {"$match": {"consume.consumeDate": {"$gte": day_180, "$lte": today}}}
match2 = {"$match": {"consume": None}}
match3 = {"$match": {"recharge.rechargeDate": {"$gte": day_30, "$lte": today}}}
match4 = {"$match": {"recharge.tradeNo": {"$ne": ""}}}
lookup1 = {"$lookup": {
"from": "consume",
"localField": "_id",
"foreignField": "uid",
"as": "consume"
}}
lookup2 = {"$lookup": {
"from": "recharge",
"localField": "_id",
"foreignField": "uid",
"as": "recharge"
}}
project = {"$project": {
"_id": 1,
"regDate": 1,
"consume.amount": 1,
"consume.consumeDate": 1,
"recharge.real": 1,
"recharge.from": 1,
"recharge.rechargeDate": 1
}}
group = {"$group": {
"_id": {
"_id": "$_id",
}
}}
pipeline = [match0, lookup1, lookup2, match1, match2, match3, match4, project, group]
result = col_user.aggregate(pipeline)
LossUser = 0
for _ in result:
LossUser = LossUser + 1
print(LossUser)