Hi im trying to use a switch statement inside of map to increment a value depending on the case but im getting
MongoServerError: $switch found an unknown argument: $$favcast
is this viable?
db.movies.aggregate([
{$match: {cast: { $elemMatch: { $exists: true } }}},
{$match:{ "tomatoes.viewer.rating": {$gte: 3}}},
{$match:{ countries: {$in: ["USA"]}}},
{$addFields: {num_favs: 0}},
{$project: {
_id: 0,
cast: {
$map: {
input: "$cast",
as: "favcast",
in: { $switch: {
$$favcast:[
{ case: "Sandra Bullock", then: { $add: [ "$num_favs", 1] } },
{ case: "Tom Hanks", then: { $add: [ "$num_favs", 1] } },
{ case: "Julia Roberts", then: { $add: [ "$num_favs", 1] } },
{ case: "Kevin Spacey", then: { $add: [ "$num_favs", 1] } },
{ case: "George Clooney", then: { $add: [ "$num_favs", 1] } },
],
default: { $add: [ "$num_favs", 0 ]}
}
}
}
}
}
},
{$match:{ "num_favs": {$gt: 0}}},
{$project: { num_favs: 1, title: 1 }}
])