broadcast users on app (query)
Thu Aug 01 2024 04:51:26 GMT+0000 (Coordinated Universal Time)
Saved by @CodeWithSachin #aggregation #mongodb #$objecttoarray #$addfiels
[ { "$lookup": { "from": "participant", "localField": "participantId", "foreignField": "_id", "as": "participants" } }, { "$unwind": { "path": "$participants", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "subscription", "localField": "participantId", "foreignField": "userId", "as": "subscriptions" } }, { "$unwind": { "path": "$subscriptions", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "subscriptionPlan", "localField": "subscriptions.planId", "foreignField": "_id", "as": "subscriptionPlans" } }, { "$unwind": { "path": "$subscriptionPlans", "preserveNullAndEmptyArrays": true } }, { "$match": { "nutritionistID": { "$oid": "64782249defe1c75d7689cbd" } } }, { "$match": { "subscriptions.planId": { "$exists": true } } }, { "$match": { "participants": { "$exists": true } } }, { "$match": { "participants": { "$exists": true } } }, { "$match": { "active": true } } ] //query 2 [ { "$lookup": { "from": "participant", "localField": "participantId", "foreignField": "_id", "as": "participants" } }, { "$unwind": { "path": "$participants", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "subscription", "localField": "participantId", "foreignField": "userId", "as": "subscriptions" } }, { "$unwind": { "path": "$subscriptions", "preserveNullAndEmptyArrays": true } }, { "$lookup": { "from": "subscriptionPlan", "localField": "subscriptions.planId", "foreignField": "_id", "as": "subscriptionPlans" } }, { "$unwind": { "path": "$subscriptionPlans", "preserveNullAndEmptyArrays": true } }, { "$match": { "nutritionistID": { "$oid": "64782249defe1c75d7689cbd" } } }, { "$match": { "subscriptions.planId": { "$exists": false } } }, { "$match": { "participants": { "$exists": true } } }, { "$match": { "participants": { "$exists": true } } }, { "$match": { "active": true } } ] for tavishi table is -> userNutrionistMapping
Comments