-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.3.4
-
Component/s: CRUD
-
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
,
{"as", "units"},
{"cond", bson.D{
{"$or", bson.A{ bson.D{{"$eq", bson.A
}},
bson.D{{"$eq", bson.A
}},
}},
}},
}},
}},
}},
}
unwindStage := bson.D
,
}
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