Lastly I’m using mongodb to build Trivia game, I’m sorting by default all the questions by last added.
I build the next query by my needs:
db.getCollection("questions").aggregate([{
$facet:
{
"data":[
{$match:{}},
{$skip:0},
{$limit:10},
{$sort:{ time_added: 1 }}
],
"filterCount":[{$match:{}}, {$group:{_id:null,count:{$sum:1}}}],
"totalCount":[{$group:{_id:null,count:{$sum:1}}}]
}
}])
Using regular query, to find data I get it order perfect by ‘time_added’, but using this sort, all the data inside ‘data’ is not order well.
Can’t find any more help in the internet.