Reputation: 6257
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?
Upvotes: 4
Views: 3663
Reputation: 5245
$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 }));
Upvotes: 8