Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35535

The aggregate pipe stops if $match has no results

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • 4.0.0-rc4
    • Aggregation Framework
    • None

    Description

      db.blacklist.aggregate([
        { $project: { contact: 1, profile: 1 } },
        { $match: { contact: 'SELF_ID_STR' }, // * if we not have result, pipe stay on whis step.
        // convert results to { _id: null, blocked_list: [idslist...] }
        { $group: { _id: null, blocked_list: { $push: { $toObjectId: '$profile' } } } },
        {
          $lookup: {
            from: 'profiles',
            as: 'profiles',
            let: { ignore: '$blocked_list' },
            pipeline: [
              // * cant use $nin in aggregate
              // * cant modify results for add self profile to exclude
              { $match: { $expr: { $not: { $in: ['$_id', '$$ignore'] } } } }
            ]
          }
        },
        { $unwind: '$profiles' },
        { $replaceRoot: { newRoot: '$profiles' } }
      ]);
      

      Attachments

        Activity

          People

            nick.brewer Nick Brewer
            focus-at Dmitry
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: