Aggregate works in mongo-compass but it does not work in MongoDB chart

Hi, I run this aggregate in the mongo-compass and it returns the right value for me but I could not use it in the MongoDB chart:

aggregate:

[
  {
    $lookup: {
      from: 'leads',
      localField: 'lead',
      foreignField: '_id',
      as: 'lookuped_lead'
    }
  },
  {
    $unwind: {
      path: '$lookuped_lead',
      preserveNullAndEmptyArrays: true
    }
  },
  { 
    $match: {
      'lookuped_lead.followUpBy': {
        $type: 'objectId'
      }
    }
  },
  {
    $lookup: {
      from: 'admins',
      localField: 'lookuped_lead.followUpBy',
      foreignField: '_id',
      as: 'lookuped_followUpBy'
    }
  },
  {
    $unwind: {
      path: '$lookuped_followUpBy',
      preserveNullAndEmptyArrays: true
    }
  },
  {
    $addFields: {
      followUpBy_info: '$lookuped_followUpBy'
    }
  }
]

NOTE: I copy and paste this aggregate in the query in MongoDB chart

I got it, you can not use lookup operator in the query bar. ridiculous. WHYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?

I try to run this query in query bar, but i got error:

[
  {
    $addFeilds: {
      '$lookuped_leads.correct_followUpBy': { 
        '$lookuped_leads.followUpBy': { $type: 'objectId' } 
      },
    }
  }
]

And this query does not add the changed_followUpBy field in the Fields section:

[
  {
    $addFields: {
      'changed_followUpBy': {
        $cond: [ 
          {
            $eq: [ {$type: '$lookuped_leads.followUpBy'}, 'objectId' ]
          },
          'wrong value in the $lookuped_leads.followUpBy',
          '$followUpBy'
        ]
      }
    }
  }
]

You can use $lookup with charts by setting up a view that has the $lookup stages.

When you say you get an error when you try something it would help to see what the error message is exactly.

Asya

2 Likes