may i have some hint on
Chapter 4: Core Aggregation - Multidimensional Grouping
Lab - $facets
???
Although we learned about sortByCount and bucket, what you asked is more like ordering and limiting…
so i did too, i made a facet and filter top 10 using order and limit strateg, and non of them return same results…
if you mean bucketing the rating and ten last bucket, not top ten item (for example, )? then how much? x in 8, + y in 8.1 + z in 8.2 … ?
then how to know the last existing backet? filtering etc…
also for my own knowledge… i wanted to filter the mixing item using $map adding new field to it say they are over lapping, or $filter filtering them out, i couldn’t come up with a working idea… any thing i should know? this lesson is harder than i think:
BTW… MY NOT WORKING CODE, WHICH ALSO DO NOT PRODUCE DESIRED RESULTS IN IT’S HALF WAY… (i don’t think is it matter if i share it as long as it is wrong):
db.movies.aggregate([{
$facet: {
imdbTop: [{
$sort: {
'imdb.rating': -1
}
}, {
$limit: 10
}, {
$project: {
rating: '$imdb.rating',
title: '$title'
}
}
],
metacriticTop: [{
$sort: {
'metacritic': -1
}
}, {
$limit: 10
}, {
$project: {
rating: '$imdb.rating',
title: '$title'
}
}
]
}
}, {
$project: {
"topBoth": {
$filter: {
input: '$imdbTop',
as: 'imdb',
cond: [{
'$$imdb.title': {
$in: '$metacriticTop.title'
}
}, true, false]
}
}
}
}
])
BTW facet and lot of other things are buggy on mongoDB Compass… the working scenario in shell, would generate ‘[’ ‘{’ error in in compass… also it eat too much memory after several command, and it wont clear out. and plus to that many of instances, you have to force end task it from task manager, other wise it won’t run.