Lab $match question: how to validate?

Finally I am able to create the match pipeline correctly and when I run db.movies.aggregate(pipeline).itcount(), I am getting 23 count, which correct.

But I am really confused the way we are asked to validate. It is my understanding that we are querying at Atlas, which is cloud server provided by mongodb.

So how can I “Load validateLab1.js into mongo shell” ? and from where I should run validateLab1(pipeline).

Solved the lab but got stuck on the validation part.

@ yutao100

You just put that in your home folder (or whatever folder you’re running the mongo shell in). The mongo shell will look there to load the JS file. Post back here if you have any problems. Good luck.

1 Like

David,

Thanks for your reply. Sorry for any stupid questions here.

I guess that I am still confused. I connected to the mongodb Atlas, which is the cloud server that is not on my local machine. Do I need to load JS file to that cloud server?

I don’t remember where I installed Mongo shell. I probably did when I took the class M101.

Here is what I can do: first, I opened a terminal on my Mac laptop, and then I run this : 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

I was able to query and run $match to get 23 counts…but then I got stuck on the validation part. Maybe I need to retake M101.

@ yutao100

So then just put the validation script in the same directory you are in on your laptop.

For example, if I open a terminal on my MacBook Pro, I’m in the directory

/Users/david

which I can see by running the command pwd. Now I just put my validateLab1.js script there. Notice that the script isn’t where I installed the mongo shell, but where I’m running the shell right now.

And if you think about it, that’s pretty much what you’d want. As a DBA, you don’t want to put debugging and testing scripts on the database server(s) – since they may have important and sensitive information – and you want to be able to run them against any of the servers you have running. HTH.

I did it this way:

–downloaded the handout “Chapter 1”. It has two files: validateLab1.js and validateLab2.js
–I opened the required file with a text editor and copied the file.
–pasted the file into the mongo shell.
–then form the mongo shell > validateLab1(pipeline)