Feature request (maybe): Populate using pipeline
We have a multi-tenanted app (multiple teams), and as an extra layer of security to ensure data integrity, we'd like to ensure that when a reference is populated, it doesn't point to another team. I figured something like this could be done with virtual fields, if $lookup pipeline could be defined. In our case we have the team field defined for almost all documents, meaning in the pipeline I could just check that the referenced document's team field is the same as the current document's team field or not. Something like this:
UserSchema.virtual('contact', {
justOne: true,
from: 'contacts',
as: 'contact',
let: {
teamId: '$team',
contactId: '$contact',
},
pipeline: [
{$match: {
_id: '$$contactId',
team: '$$teamId'
}}
]
})
Question: Is this supported currently, or are there plans to support it?
We do not currently support this, we may add support in the future. Thanks for the suggestion!
@vkarpov15 Any plan on this new feature?
Not currently. We're unlikely to prioritize this issue, because we don't want to use $lookup for populate(). Can you please describe your use case @ghostoy ?