Trying to write a query that allows me to see ONLY the month and the icecream_sales_in_millions

Hi. In the icecream_data, I am trying to write a query that allows me to see ONLY the month and the icecream_sales_in_millions sorting on the latter in an descending order. I have tried to write in so many way. The following query doesn’t issue anu error, YET, it doesn’t do what I want! Why??

db.icecream_data.aggregate([
    {"$project": {
        _id:0,
        "trends.month": 1,
        "trends.icecream_sales_in_millions": 1}
    },
    {$sort: {
        "trends.icecream_sales_in_millions": -1
    }}
]).pretty()

Thanks for your help!
Rhonda

Not sure if this is what you want but try https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/ on the array before the sort.

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