Chapter2 - Lab1

I am getting stuck here, After spending good amount of time researching, trial and error, i came up with following pipeline, but it shows incorrect movie since it is not one of the multiple choices…can someone tell me what is that i am going wrong?

[{
$project: {
“_id”: 0,
“countries”: 1,
“tomatoes.viewer.rating”: 1,
“cast”: 1,
“title”: 1

}

}, {
$match: {
“countries”: “USA”,
“tomatoes.viewer.rating”: {
‘$gte’: 3
},
“cast”: {
‘$in’: [“Sandra Bullock”, “Tom Hanks”, “Julia Roberts”, “Kevin Spacey”, “George Clooney”]
}
}
}, {
$addFields: {
“num_fav”: {
$size: {
$setIntersection: ["$cast", [“Sandra Bullock”, “Tom Hanks”, “Julia Roberts”, “Kevin Spacey”, “George Clooney”]]
}
},
}
}, {
$sort: {
“num_fav”: -1,
“tomatoes.viewer.rating”: -1,
“title”: -1
}
}, {
$limit: 25
}, {
$skip: 24
}]

Hi @Jatin_73145,

I didn’t go through the full pipeline, but to see the element 25, skip 24 and limit 1, right?


Also, I’d recommend blur the code using this syntax

[spoiler]
Your Code Here
[/spoiler]

Hi,
It worked for me:

[{$match: { "tomatoes.viewer.rating": {$gte: 3}, countries: "USA", cast: { $in:[ "Sandra Bullock", "Tom Hanks", "Julia Roberts", "Kevin Spacey", "George Clooney"] } }}, {$project: { "_id": 0, title: 1, "rating": "$tomatoes.viewer.rating", countries: 1, cast: 1 }}, {$addFields: { num_favs: { $size: { $setIntersection: ["$cast", [ "Sandra Bullock", "Tom Hanks", "Julia Roberts", "Kevin Spacey", "George Clooney"]] } } }}, {$sort: { num_favs: -1, "rating": -1, title: -1 }}, {$skip: 24}, {$limit: 1}]

It does work but result is not right. The movie name is not part of multiple choices

Hello @Jatin_73145 !

Can you share your new snippet? Just re writing using ^^^^ I’m getting one of the options.

its the same pipeline, i am not sure what logic is wrong but i am doing something wrong…

[{
$project: {
“_id”: 0,
“countries”: 1,
“tomatoes.viewer.rating”: 1,
“cast”: 1,
“title”: 1

}

}, {
$match: {
“countries”: “USA”,
“tomatoes.viewer.rating”: {
‘$gte’: 3
},
“cast”: {
‘$in’: [“Sandra Bullock”, “Tom Hanks”, “Julia Roberts”, “Kevin Spacey”, “George Clooney”]
}
}
}, {
$addFields: {
“num_fav”: {
$size: {
$setIntersection: ["$cast", [“Sandra Bullock”, “Tom Hanks”, “Julia Roberts”, “Kevin Spacey”, “George Clooney”]]
}
},
}
}, {
$sort: {
“num_fav”: -1,
“tomatoes.viewer.rating”: -1,
“title”: -1
}
}, {
$limit: 25
}, {
$skip: 24
}]

I see, thanks for blurring.

Try skip 24, and then limit 1