[GODRIVER-1673] The Filter query on nested sub-document array is not returning results Created: 07/Jul/20  Updated: 08/Jul/20  Resolved: 07/Jul/20

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 1.3.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Abhay Kumar Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows



 Description   

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 

 

 

 

 



 Comments   
Comment by Abhay Kumar [ 08/Jul/20 ]

I just updated the issues details if that help and posted above.

Comment by Abhay Kumar [ 08/Jul/20 ]

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.primaryID", "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.primaryID doesn't return any response

If we pass "1234"
 
"$elemMatch" works fine with assetsReserved.assets.primaryID and is able to return result however it returns only 1 record even when multiple records with same primaryID 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 

Comment by Abhay Kumar [ 08/Jul/20 ]

How is it a support issue? The filtering query on array element withing a sub document is not returning results. I think it requires investigation on your side 

Comment by Jeffrey Yemin [ 07/Jul/20 ]

Hi there, thank you for reaching out. As this sounds like a support issue, I wanted to give you some resources to get this questioned answered more quickly:

  • our MongoDB support portal, located at support.mongodb.com
  • our MongoDB community portal, located here
    -If you are an Atlas customer, there is free support offered 24/7 in the lower right hand corner of the UI.

Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.

Thank you!

Generated at Thu Feb 08 08:36:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.