Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const pipeline: object[] = [
- {
- $match: {
- active: true,
- platformId: new mongodb.ObjectID(platformId),
- },
- },
- {
- $lookup: {
- from: 'retailers',
- localField: 'retailerId',
- foreignField: '_id',
- as: 'retailer',
- },
- },
- {
- $unwind: {
- path: '$retailer',
- }
- },
- {
- $match: {
- 'retailer.active': true,
- }
- },
- {
- $lookup: {
- from: 'dictionaryretaileroptions',
- localField: 'optionListId',
- foreignField: '_id',
- as: 'optionList',
- },
- },
- {
- $lookup: {
- from: 'coupons',
- let: {'retailerOnPlatformId': '$_id'},
- pipeline: [
- {
- $match: {
- $expr: {
- $and: [
- {$eq: ['$retailerOnPlatformId', '$$retailerOnPlatformId']},
- {$eq: ['$active', true]},
- {$lte:['$dateStart', currDate]},
- {$gte:['$dateEnd', currDate]},
- ]
- }
- }
- }
- ],
- as: 'coupons',
- },
- },
- {
- $match: {
- ...match,
- },
- },
- {
- $limit: limit
- },
- {
- $project: {
- slug: 1,
- imageText: 1,
- retailerId: '$retailer._id',
- name: '$retailer.name',
- alternativeName: '$retailer.alternativeName',
- image: '$retailer.image',
- categoryListId: '$retailer.categoryListId',
- sliderImage: 1,
- // bannerImage: 1,
- landingsSort: 1,
- couponCount: {$size: '$coupons'},
- },
- },
- // {$match: {'couponCount': {$gt: 0}}}
- ];
Advertisement
Add Comment
Please, Sign In to add comment