I am currently working on associating a populated referenced document with the parent document id. The main objective is to display only the membership permissions related to a specific organization, rather than showing all other permissions that may exist. This means that the 'entity.item', which represents an organization in this case, should be linked to the parent organization id. I am exploring ways to access the parent organization id from a child document.
let userId = '123';
let organizations = await Organization.find().where('members.includes(userId)').populate({
path: 'members',
options: { sort: { name: 1 } },
populate: {
path: 'permissions',
match: {
'entity.kind': 'Organization',
'entity.item': organization._id //HERE
},
populate: {
path: 'entity.item'
}
}
});