When I perform a sort using a project fields value like this:
[{
'$project': {
'metaData': {
'$let': {
'vars': {
'array': []
},
'in': {
'sizeArray': {
'$size': '$$array'
}
}
}
}
}
}, {
"$sort": {
"metaData.sizeArray": 1
}
}].
Here I perform a sort using the size of the array. In this example the size of the array is zero, but it can vary if the array is made out of value of a field in the collection.
Everything works fine until now. But if I perform $skip then $limit after this many documents are repeated when the value of $skip changes. For example:
db.getCollection('venues').aggregate([{ '$project': { 'metaData': { '$let': { 'vars': { 'array': [] }, 'in': { 'sizeArray': { '$size': '$$array' } } } } } }, { "$sort": { "metaData.sizeArray": 1 } }, { "$skip": 4 }, { "$limit": 4 }]);
When the value of skip goes from 4..8..12, many documents are repeated.