In chapter 3 in the lecture the data seem to be unsanitized so I tried to clean it up a bit
db.movies.aggregate([{
$addFields: {
year: {
$convert: {
input: "$year",
to: "int"
}
}
},
{
$group: {
_id: {
year: "$year",
runtime: {
$cond: [{ $eq: [{ $type: "$runtime" }, "int"] }, "$runtime", 0]
}
},
num_films_in_years: { $sum: 1 },
averageRuntime: { $avg: "$runtime" }
}])
In short, I want to convert all year data to number because some year data contain strange letter which make it unable to group. But execute the code above gave me an error
"errmsg" : "Unrecognized expression '$convert'"
Which seem strange to me as why it doesn’t recognize $convert.
So why this error message happen, and is there any way to fix this?