Mongodb: $filter is not allowed in this atlas tier

Viewed 2865

I run a query that return an array of users through an aggregation. In order not to return the document of the user performing the query, I added a $filter on his id. But I receive the following error:

$filter is not allowed in this atlas tier.

I am connected to a free MongoAtlas cluster. Here is my code.

 User.aggregate([
        { $filter: { _id: { $eq: id } } },
        {
          $match: {
            jobs: { $in: jobs },
           age: { $gte: minAge, $lte: maxAge },
          },
        },
      ]).exec((_, data) => res.json({ data }));

How to fix this?

1 Answers

$filter is not a pipeline stage, it's for filtering an array expression. You can just put what you are trying to filter in the $match stage.

 User.aggregate([
        {
          $match: {
            _id: id,
            jobs: { $in: jobs },
            age: { $gte: minAge, $lte: maxAge },
          },
        },
      ]).exec((_, data) => res.json({ data }));
Related