Tuesday, 6 June 2017

How can i do group with sum after lookup in mongodb?

db.transections.aggregate(
    [

        {
            $lookup: {
                from: "activitylogs",
                localField: "transectionid",
                foreignField: "ref_id",
                as: "point"
            }
        },

        {
            $group: {
                _id: {
                    mobilenumber: "mobilenumber"
                },
                amount: {
                    $sum: "transectionamount"
                },
                points: {
                    $sum: "point.givenpoint"
                },
                count: {
                    $sum: 1
                }
            }
        }

    ]
)

here i am trying to get sum of transectionamount and givenpoint but when i run this query this is not giving any result .

mobilenumber and transectionamount are available in transections collection

givenpoint available in activitylogs collection

how can i query get sum of transectionamount and givenpoint any one help me out



via koo 005

No comments:

Post a Comment