$sort is not working correctly on mongo db aggregate stages

#1

Hello,

I has been trying to execute below query but failed
{
“collection”: “projects”,
“aggregate”: [
{
“$project”: {
“title”: 1,
“likes”: {
“$size”: “$likes”
}
}
},
{
“$sort”: { “likes”: 1 }
}
]
}

This works on MongoDB Compass.

Can you fix it?

0 Likes

#2

It could help if you can share more information on how this failed? Did it return some error message? Did it return the wrong results?

0 Likes

#3

Can you try this syntax:

{
  "$sort": { 
    "name": "likes",
    "direction": 1
  }
}
0 Likes

#4

Error running query: string indices must be integers

0 Likes

#5

Did you ever work this out @Digitz?

0 Likes