I have this aggregation query:
db.getCollection('collectionName').aggregate([
{
$facet: {
"myAttrName": [
{
$match: {
$or: [
{
"key1": "value1"
},
{
"key2": "value2"
}
],
status: "OK"
}
},
{
$skip: 0
},
{
$limit: 10
},
{
$sort: {
timestamp: -1
}
}
]
}
}
])
Well.. it doesn't sorts the results properly. I just see them ordered by time of adding them "fifo".
When Im just doing regular find (no aggregation) with .sort({timestamp: -1}) it works properly.
What am I missing in here?
$sortstage to before$skipstage.$facet. In a "classic" pipeline it would have worked well docs.mongodb.com/manual/core/aggregation-pipeline-optimization