The aggregate pipe stops if $match has no results

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: 4.0.0-rc4
    • Component/s: Aggregation Framework
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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' } }
      ]);
      

              Assignee:
              Nick Brewer (Inactive)
              Reporter:
              Dmitry
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: