Hi,
I am right now at chapter4 lecture 2.
I have come across ‘$sortByCount’ but I don’t understand what difference does it make in real with $group
For Example:
Using $sortByCount:
db.companies.aggregate([{
$match: {
$text: {
$search: ‘network’
}
}
}, {
$sortByCount: ‘$category_code’
}])
Using $group:
db.companies.aggregate([{
$match: {
$text: {
$search: ‘network’
}
}
}, {
$group: {
_id: ‘$category_code’,
count: { $sum: 1 }
}
},
{
$sort: {
count: -1
}
}])
I simply feel that if I am using ‘$group’ I have to add some more lines of code to achieve the result.
What is the difference between ‘$group’ and ‘$sortByCount’?