MongoServerError: count is not allowed in this atlas tier

I watched the video Getting Started with GDELT MongoDB, in it they create in MongoDB Compass an Aggregation called EventsGroupedBySource, I also do the same but using the data from my own cluster and works ok.

I tried to replicate in my code Node.js the same:

const newsWithAggregationBySourceUrl = await collection.aggregate([{$group:{
_id: “$SOURCEURL”,
count: {
$sum: 1
},
ids: {
$push: { id: “$_id”, code: “$EventCode”}
}
}}, {
“count”: { $gt: 1}
}]).toArray();

But I got the following error:

MongoServerError: count is not allowed in this atlas tier

Why I am able to create the Aggregation in MongoDB Compass but not in my code?

Is there an alternative to perform this query?

Thanks

Your stage count:{$gt:1} is not a valid stage.

If you want to filter documents, you must use a $match stage.

1 Like

Thanks for your answer, I don’t want filter documents, what I would like is to group documents with the same SOURCEURL., like in the image below:

That image is a $match stage with you count query.

The box you circled in red reads Output after $match stage.

All right, I understand you know, the following code works ok:

const newsWithAggregationBySourceUrl = await collection.aggregate([{$group:{
_id: “$SOURCEURL”,
count: {
$sum: 1
},
ids: {
$push: { id: “$_id”, code: “$EventCode”}
}
}}, {$match:{
“count”: { $gt: 1}
}}]).toArray();

Thank you very much for your help.

2 Likes

Thanks for the help @steevej

Glad you got sorted @Manuel_Martin

1 Like

Thanks, I also discovered a bit later and I would like to share because ca help others that MongoDB Compass has the functionality to Export Pipeline to several languages that is a great help to build the queries in code.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.