Lab - $match - validateLab1(pipeline) command running forever

Hi
I have 2 issues
First, for

  • imdb.rating is at least 7
  • genres does not contain “Crime” or “Horror”
  • rated is either “PG” or “G”
  • languages contains “English” and “Japanese”
    I got 18 records after running db.movies.aggregate(pipeline).itcount()

Second, I am on windows 10 and run
MongoDB Enterprise mflix-shard-0:PRIMARY> load(‘D:\MongoDB\Queries\validateLab1.js’)
returned true
I assume script was loaded but when run
MongoDB Enterprise mflix-shard-0:PRIMARY> validateLab1(pipeline)
it does not complete and freeze forever so I need to kill it

Can you explain why? What did I do wrong?

Hey @Jacob_32894

Straight from the lab

As a hint, your aggregation should return 23 documents. You can verify this by typing db.movies.aggregate(pipeline).itcount()

So perhaps your pipeline is incorrect.

And

I would agree that I believe it has loaded.

If you are still having issues after looking at your pipeline, and you believe it to be right, then feel free to get back to me. You can put print() statements inside the validateLab1.js file if all else fails…

1 Like

Hi @Jacob_32894,

In addition to @natac13’s reply, make sure that you are connected to the correct cluster. Please use the following connection string:

mongo “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

After connecting to the m121 course Atlas cluster using the above connection string, create the pipeline using the $match stage.

Please let me know, if you have any questions.

Thanks,
Sonali

1 Like

Attention Sean Campbell

Hi Sean

Thanks for quick response

Below is my condition

var pipeline = [{ $match: }]

Can you advise what part is wrong?

I will try to put print into .js

Thanks

Jacob

@Jacob_32894

So that pipeline is looking good, and on that note please remove it so no one else gets the answer.

However it is given you 18 instead of 23? Let me try it out and ill get back to you.

@Jacob_32894

Ok So I have use the connection command provide by @Sonali_Mamgain And got connected fine.

mongo "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

Then I assigned your exact pipeline(minus changing the fancy quotes to normal) to a variable and ran

var pipeline = [... what you should delete from the post since it is the answer]
db.movies.aggregate(pipeline).itcount()

Got 23!

So try with the above connection command and load your pipeline again and use it against the movies collection in the aggregations db

You can check what database you are using in the mongo shell by running

db

Thanks, I removed my pipeline
I will verify connection string

Thanks
Jacob

1 Like

Hi Sean, Sonali_48808, Natac13
The major issue was there are 2 collections movies - one in mflix and another in aggregations - I was in mflix (wrong one)
Thanks for your help!

1 Like