Well, I am going at this for at least two hours and I cannot figure it out. I am getting the right query statement but the numbers don’t make sense. Need a second pair of eyes to figure what I’m doing wrong. Below is a screenshot of the result which generated by the lines below it. The problem I have is that “normalized_rating” (which is the an average of the “rating” and the “scaled_votes”, or so it says in the instructions) is showing as the “rating”; the average should be the addition of the “rating” plus the “scaled_votes” divided by 2. So either there is something wrong in my statement or the $avg operator is messed up. BTW, I tried replacing the average with a simple division (it’s only 2 values) and the result of the “normalized_rating” is null. I am at a loss! Please help…
{
$addFields: {
rating: "$imdb.rating",
votes: "$imdb.votes"
}
},
{
$project: {
_id:0,
title: 1,
rating: 1,
votes: 1,
year: 1,
scaled_votes: {
$add : [
1,
{
$multiply: [
9,
{
$divide: [
{$subtract: ["$votes", 5]},
{$subtract: [1521105, 5]}
]
}
]
}
]
},
normalized_rating: {
$avg: ["$scaled_votes", "$rating"]
}
}
},