Chapter 4: CRUD Optimization Lab 4.2: Aggregation Performance

On Compass I cannot run the following in Explain Plan Tab, why?
{ $match: { stars: { $gt: 2 } } }, { $sort: { stars: 1 } }, { $group: { _id: “$cuisine”, count: { $sum: 1 } } }

It gives me an error:
Error getting filter : Expected ‘filter’ to be BSON (or equivalent), but got primitive.A instead. Doc = [{find restaurants} {filter [[{$match [{stars [{$gt 2}]}]}] [{$sort [{stars 1}]}] [{$group [{_id $cuisine} {count [{$sum 1}]}]}]]} {maxTimeMS 5000} {returnKey false} {showRecordId false}]

Then, I cannot run on mongoShell the following command with explain()

db.restaurants.aggregate([
{ $match: { stars: { $gt: 2 } } },
{ $sort: { stars: 1 } },
{ $group: { _id: “$cuisine”, count: { $sum: 1 } } }
]).explain(“executionStats”)

It gives me an error as well.

How am i suppose to check for performance if everything gives me errors?
Help please!

Screenshot of the error you get in mongo shell.

Here is the screenshot:

I was able to get some results using this command:

db.restaurants.aggregate([ { $match: { stars: { $gt: 2 } } }, { $sort: { stars: 1 } }, { $group: { _id: “$cuisine”, count: { $sum: 1 } } }], {explain:true} )

However, how do i use explain with “executionStats”

Try this

db.collection.explain().aggregate(…)
db.collection.explain(‘executionStats’).aggregate(…)

1 Like

Hi
Myself Ayan, I am going through the videos sessions and the quiz section.
I have doubt on the Covered Queries quiz section, can you explain the 3rd and the 4th option in that quiz and why is the 4th one right

Hi @Ayan_Gorai,

I have initiated a discourse inbox thread with you. Please respond there if you have any further questions.

Kind Regards,
Sonali