How can I create a reference based on multiple foreign fields? #941
Answered
by
hasezoey
tomerh2001
asked this question in
Q&A
-
I have the following mongodb query in my code: await ActivityPlatformModel.find({
activityId: context.activity._id,
platformId: context.platform.id,
}); It is basically redundant since I can use @plugin(autoPopulate)
export class ActivityPlatformReference {
@prop({
ref: () => ActivityPlatform,
localField: 'activityId',
foreignField: '_id',
autopopulate: true,
})
platform?: ActivityPlatform[];
@prop({type: () => Types.ObjectId})
activityId!: Types.ObjectId;
@prop({type: () => String})
platformId!: PlatformId;
} But I can't seem to find a way to specify that I need both How does one do multi-field references in Mongoose/Typegoose? |
Beta Was this translation helpful? Give feedback.
Answered by
hasezoey
May 17, 2024
Replies: 1 comment 2 replies
-
i have not personally needed to do this, but you might wanna look into the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tomerh2001
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i have not personally needed to do this, but you might wanna look into the
match
option and read Populate Virtuals: The Match Option