Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reverse lookup: https://stackoverflow.com/questions/63364037/mongoose-aggregation-reverse-lookup-or-lookup-without-localfield
- const tags = await TagSchema.aggregate([
- {
- from: 'posts',
- let: { tagId: '$_id' },
- pipeline: [
- {
- $match: {
- $expr: {
- $eq: ['$_id', '$$tagId'],
- },
- },
- },
- {
- $project: {},
- },
- ],
- as: 'posts',
- },
- {
- $unwind: {
- path: '$posts',
- preserveNullAndEmptyArrays: true,
- },
- },
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement