Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1673

The Filter query on nested sub-document array is not returning results

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.3.4
    • Component/s: CRUD
    • Labels:
      None
    • Environment:
      Windows

      The data is stored as:

      {    "_id":\{"$oid":"5e7b22bd2a7912a5a3b73d79"}

      ,
         "manufacturerID":"19193",
         "units":[
                        {
                            "assetsReserved":{
                                      "departmentCode" : "PHY_DEPTS",
                                      "assets":{"primaryID":"1234"}}
                        },
                       {
                                "departmentCode" : "PHY_DEPTS",
                                "assetsReserved":{"assets":{"primaryID":"4567"}}
                       }
                   ]
      }
      The requirement is to get all the units where primaryID matches the "1234"

      The mongo.Pipeline is made up of 
       
      matchStage := bson.D{primitive.E{Key: "$match", Value: bson.D{primitive.E{Key: "manufacturerID", Value: "19193"}}}}

      projectStage := bson.D{
                                            {"$project", bson.D{
                                                                    {"units", bson.D{
                                                                                 {"$filter", bson.D

      {                                                                            \{"input", "$units"}

      ,
                                                                                 {"as", "units"},
                                                                                 {"cond", bson.D{
      {"$or", bson.A{                                                                                                        bson.D{{"$eq", bson.A

      {"$$units.assetsReserved.departmentCode", "1234"}

      }},
      bson.D{{"$eq", bson.A

      {"$$units.assetsReserved.assets.primaryTrackingID", "1234"}

      }},
      }},
      }},
      }},
      }},
      }},
      }
      unwindStage := bson.D

      { \{"$unwind", "$units"}

      ,
      }

      The search based on 

      units.assetsReserved.departmentCode works

      If we pass "PHY_DEPTS" we get the response, however 

      units.assetsReserved.assets.primaryTrackingID doesn't return any response

      If we pass "1234"
       
      "$elemMatch" works fine with assetsReserved.assets.primaryTrackingID and is able to return result however it returns only 1 record even when multiple records with same primaryTrackingID exists which is the expected behavior based on documentation.
      Looks like issues with $filter and cond that its not able to filter when subdocument contains an array 

       

       

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            abhay.kumar1@pb.com Abhay Kumar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: