I facing a weird problem in this query can anyone help me please

 var sellReportData = await SingleDigit.aggregate([
   {
      "$lookup":{
         "from":"bidhistories",
         "let":{
            "number":"$single_digit"
         },
         "pipeline":[
            {
               "$match":{
                  "$expr":{
                     "$and":[
                        {
                           "$eq":[
                              "$digits",
                              "$$number"
                           ]
                        },
                        {
                           "$eq":[
                              "$game_id",
                              "game_name"
                           ]
                        },
                        {
                           "$eq":[
                              "$session",
                              "market_status"
                           ]
                        },
                        {
                           "$eq":[
                              "$bid_date",
                              "bid_date"
                           ]
                        },
                     ]
                  }
               }
            },
            {
               "$group":{
                  "_id":"$digits",
                  "totalAmount":{
                     "$sum":"$points"
                  }
               }
            }
         ],
         "as":"sellReport"
      }
   },
   {
      "$sort":{
         "sellReport.totalAmount":-1
      }
   }
])

The code that is bold in this query is must for me as where condition with join table but when i am using this then i am not able to fetch data whatever i am looking for can anybody help me what i am doing wrong in this.

Thanks in advance.

Welcome to the MongoDB Community @Kashif_Zaki !

To help understand your issue can you please provide:

  • sample documents for both collections in the aggregation
  • expected output
  • version of MongoDB server

To troubleshoot your aggregation pipeline, I would also check the output after each stage to make sure it is as expected. The Aggregation Pipeline Builder in MongoDB Compass is a helpful (and free) tool for this.

Thanks,
Stennie