Chapter 2 Lab 1


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

I did not get any answer or error it just finished processing and shows again PRIMARY>

Please help me for this.

1 Like


This command produces no output either:


I did not understand hint. Can you explain me where code is wrong? Is there something missing to execute program?

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

You did quite well.

But tomatoes.viewers.rating does not exist either. The point here is, carefully inspect the data, it will be useful in and out of the course.

Use findOne(), find().limit(), $sample, Compass or Atlas. Or any other way you find useful.

$in:["USA"] is the same as just "USA". $in is useful for multiple values. You may test this because I can be confused.

1 Like

You did not but you still changed the field name from country to countries.

1 Like

@Raj_Kadecha , Hey , what do you intend to do with this piece of code , exactly ?


cast: {$in: [“Sandra Bullock”, “Tom Hanks”, “Julia Roberts”, “Kevin Spacey”, “George Clooney”]}

I don’t think that is any different from :

{$or : [{cast : "Tom Hanks"}, {cast : "Julia Roberts"},{cast : "Sandra Bullock"},{cast : "Kevin Spacey"}, {cast : "George Clooney"} ]}

It is always best to check with the documentation.