Sorting understanding

Hello, i would like to understand why the sort stage is not working as espected.

There is my pipeline

[
{
$match: {
run_id: ObjectId(
“6792948b69f10e391dd60330”
),
},
},
{
$match: {
$expr: {
$and: [
{
$eq: [
“$find.vulnerability”,
“SQL Injection”,
],
},
],
},
},
},
{ $sort: { vuln_id: 1 } },

]

When i have the sort stage activated basiclaly some documents with lower vuln_id are at the end of the results.

I would like to understand why works like that.

Thaks

Share the sample documents that show

@Agustin_Miguel, after 7 days without a reply to my followup request, I can only imagine that you either found the solution or that your problem was not really that important.

If you found the solution by yourself or elsewhere please share and mark your shared post as the solution. Otherwise please followup.

Without further details, I can think of 1 situations where this could be the case.

Numbers stored as strings do not have the same order as numbers stored as numbers.

For example, vuln_id:‘3’ will come after vuln_id:‘21’ but vuln_id:3 will come before vuln_id:21.

For example in js we have:

nodejs> '21' > '3'
false
nodejs> 21 > 3
true
1 Like