Aggregate query working on robo3T but not working in my code

Viewed 136

I am trying to execute the aggregate query mentioned in the below, i am getting empty array. if i run the same query in the robo3T, I am getting the values. please Help me to find what am I missing.

Query:

var monthData=new Date();
            console.log(new Date(monthData.getFullYear(), monthData.getMonth(), 2).toISOString());
             monthData=await new Date(monthData.getFullYear(), monthData.getMonth(), 2).toISOString();
        [err, data] = await to(LeadsLog.aggregate(
            [
                { "$match": { "updatedAt":{$gte:monthData} }},
                { "$lookup": {
                    "from": "results",
                    "localField": "result",
                    "foreignField": "_id",
                    "as": "result"
               }},
               { "$match": { "result.company": new mongoose.Types.ObjectId(companyId)}},
                { "$group": { 
                    "_id": "$result.name",
                    "count": { "$sum": 1 }
                }}
            ]))

Robo3T Query:

db.getCollection('leadsLog').aggregate(
            [
                { "$match": { "updatedAt":{$gte:ISODate("2021-10-01T04:36:14.224Z")} }},
                { "$lookup": {
                    "from": "results",
                    "localField": "result",
                    "foreignField": "_id",
                    "as": "result"
               }},
               { "$match": { "result.company":ObjectId("6114dc9193a52d3278aa486f")}},
                { "$group": { 
                    "_id": "$result.name",
                    "count": { "$sum": 1 }
                }}
            ])

Please Help me, Thank you.

0 Answers
Related