I Don't know what goes wrong

What’s wrong with it …

Hi @Jai_59226,

I can’t test answer but a few ideas:

  • that’s not targeting released in USA
  • you need the $size of “num_fav”

Also, I’d include it straight on $project. Something like:

{ 
$project:{
  title:1,
  cast:1,
  num_fav:{
    $size:{
      $setIntersection:[$cast, ["people here..."]]
      }} 
}
2 Likes

Hi @Jai_59226,

@Santiago_Miranda has explained the issues in your pipeline.

Please feel free to reach out if you have any additional questions.

Kind Regards,
Sonali

1 Like

[{$match: {
“tomatoes.viewer.rating”: {$gte: 3},
“cast”: {$in: [
“Sandra Bullock”,
“Tom Hanks”,
“Julia Roberts”,
“Kevin Spacey”,
“George Clooney”]},
“countries”: {$eq: [“USA”]}
}}, {$project: {
“title”:1,
“cast”:1,
“countries”: 1,
“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
}}, {$skip: 24}]

I also try but … its not working

Ok. Follow this steps:

  • please only post queries with straight double quotes " or we can’t test
  • remember you can do this in the shell:
const people = [
"Sandra Bullock", 
"Tom Hanks", 
"Julia Roberts", 
"Kevin Spacey", 
"George Clooney"
]

and use the alias (variable) people wherever you want that array.

Also, this:

better be "countries": ["USA"] or "countries":"USA". It’s just a detail.

Main issue is tomatoes.viewer.rating not being projected

hence that’s not being used in the sort. I rewrote it like this:

	{
		"$project" : {
			"title" : 1,
			"cast" : 1,
			"rating" : "$tomatoes.viewer.rating",
			"countries" : 1,
			"num_fav" : {
				"$size" : {
					"$setIntersection" : [
						"$cast", people
					]
				}
			}
		}
	}

Where people, is the variable used above.

Beware, I renamed rating:"$tomatoes.viewer.rating" hence you need to sort using rating:-1. Hope that’s clear.


Something else!

You could add a limit-one stage at the end, let you work that out.

Once that’s all fixed, try, and come back if there is still any issue :slight_smile:

1 Like

Thank you So much your are great, I just changed “countries”: “USA” But i think that problem is that we find movies released in “USA” but also other countries can be included like [“USA”, “Japan”] .etc … And thanks you so much for your help… :grinning:

1 Like