I want to run aggregation on Plan Schema and fetch a Feedback that has reference Id planId
.
But If I want to populate with lookup I need the reference ID in Plan but I don't like this strategy of saving reference Id, I like everything seperated.
Is there any way to populate without having reference Id.
something like this. but It doesn't work.
const pipe = [
{
$lookup: {
from: 'Feedbacks',
pipeline: [
{
$match: {
planId: '$_id'
}
}
],
as: 'feedback'
}
}]
await Plan.aggregate(pipe);
export interface Plan {
_id: ObjectId;
...
}
export interface Feedback {
planId: ObjectId;
...
}