Lab: Using Cursor like stages | Answer not in the options

Hi ,

I am running the following things on the terminal ,

var favorites = [ ‘Sandra Bullock’, ‘Tom Hanks’, ‘Julia Roberts’, ‘Kevin Spacey’, ‘George Clooney’]

var pipeline = [
{$match : {‘tomatoes.viewer.rating’: {$gte : 3}, countries: ‘USA’, cast: {$in : favorites}}},
{$addFields : {num_favs : {$size : {$setIntersection : [’$cast’, favorites]}}}},
{$sort : {num_favs: -1, ‘tomatoes.viewer.rating’:-1, title:-1}},
{$limit : 25},
{$project:{_id:0, cast:1, countries:1, num_favs:1, ‘tomatoes.viewer.rating’:1, title:1}}
]

db.movies.aggregate(pipeline)

Help me understand what’s going wrong with this query. I am getting any of the options in the answer

Hello @vamsi_pramod and welcome to the MongoDB Community forums! :wave:

Can you explain why you don’t think that the answer you feel is correct is not in the list of options for the answer? I only ask because I see the correct answer in your results.

Hi @Doug_Duncan ,

I am getting the following as the 25th Document , which is none of the options.

{
title: ‘Saving Mr. Banks’,
cast: [
‘Emma Thompson’,
‘Tom Hanks’,
‘Annie Rose Buckley’,
‘Colin Farrell’
],
countries: [ ‘UK’, ‘Australia’, ‘USA’ ],
tomatoes: { viewer: { rating: 4 } },
num_favs: 1
}

Note : I am using the below connection string to connect

mongosh "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl -u m121 -p aggregations --norc

That is the 20th document in the list, not the 25th. The mongosh will return only 20 documents at a time. You should see the message Type "it" for more underneath the results. This means that there are more documents to be returned. Once you type it on the command line you will see the other 5 documents.

Once you do that you should see your answer. :wink:

2 Likes

Thanks!! @Doug_Duncan , was thinking default was 25
Used {$skip: 24} for better clarity. :wink:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.