In groupMember Model i try to populate group details and i apply match condition but if match condition failed then records also comes in result i dont wan't those records.
suppose group have eStatus D then IgroupId becomes null but record come.
outputs given below
const groups = await GroupMembers.find({ iUserId: ObjectId(id) })
.populate({
path: 'iGroupId',
select: '-__v',
match: { eStatus: { $in: ['Y', 'N'] } }
})
Output
[
{
"_id": "6298ad4ae7d755f6f3b46dda",
"iUserId": "629465fe89062bd576a5954a",
"iGroupId": {
"_id": "6298aca5e7d755f6f3b46dca",
"sGroupName": "Maldives from jay1",
"eGroupType": "Trip",
"sGroupAvatar": "v1654173001/userAvtars/wtkgrqqfjjspjswfbme4.jpg",
"dCreatedAt": "2022-06-02T12:27:17.560Z",
"dUpdatedAt": "2022-06-02T12:30:01.682Z",
"eStatus": "Y"
},
"eUserStatus": "Y",
"dCreatedAt": "2022-06-02T12:30:02.119Z",
"dUpdatedAt": "2022-06-02T12:30:02.119Z",
"__v": 0
},
{
"_id": "6299caeb3706f2e0d7972d68",
"iUserId": "629465fe89062bd576a5954a",
"iGroupId": null,
"eUserStatus": "Y",
"dCreatedAt": "2022-06-03T08:48:43.126Z",
"dUpdatedAt": "2022-06-03T08:48:43.126Z",
"__v": 0
}
]