Please note that, while we’ve labeled this as a lab, it is ungraded. This writeup is here simply to get you started on creating an Atlas cluster.
Once you have completed the registration form, in the next page that appears, you will be asked to choose a new group name. We use groups to manage access to Atlas clusters. Please use the name, m001-sandbox.
提醒
2018-08-23 15:58:34
在 Atlas 里我们不需要再输入 group name,只需要点击 New Project 创建 project,然后创建 cluster 即可
Once you have created a group, in the next page, enter the name, Sandbox for your cluster.
Note that we do not generally recommend opening an Atlas cluster to allow access from anywhere. We do that for this class to minimize network issues that you might run into.
Problem:
How many documents in video.movieDetails match the filter {genres: “Comedy”}?
Answer:
detailed answer:
If you have loaded the movieDetails collection, the filter {genres: “Comedy”} will match 749 documents.
Problem:
If the collection video.myMovies is currently empty, how many documents would be inserted by the following call to insertMany().
db.myMovies.insertMany( [ { "_id" : "tt0084726", "title" : "Star Trek II: The Wrath of Khan", "year" : 1982, "type" : "movie" }, { "_id" : "tt0796366", "title" : "Star Trek", "year" : 2009, "type" : "movie" }, { "_id" : "tt0084726", "title" : "Star Trek II: The Wrath of Khan", "year" : 1982, "type" : "movie" }, { "_id" : "tt1408101", "title" : "Star Trek Into Darkness", "year" : 2013, "type" : "movie" }, { "_id" : "tt0117731", "title" : "Star Trek: First Contact", "year" : 1996, "type" : "movie" } ], { ordered: false } );
Answer:
detailed answer:
There are duplicate _id values for the two entries for “Star Trek II: The Wrath of Kahn”. The second instance of this movie appearing in the array will not be inserted. However, since we are specifying that insertMany() should perform an unordered insert, all other documents will be inserts for a total of 4.
Problem:
Explore the movieDetails collection that you loaded into your Atlas sandbox cluster and then issue a query to answer the following question. How many movies in the movieDetails collection are rated PG and have exactly 10 award nominations?
You will find the count() method useful in answering this question using the mongo shell.
Answer:
detailed answer:
You can find this answer in either the mongo shell or in Compass.
In the shell, assuming you’ve loaded movieDetails into the video database and assuming you are connected to your Atlas sandbox cluster, you can issue the following query.
db.movieDetails.find({rated: “PG”, “awards.nominations”: 10}).count()
In Compass you can use the following filter in the Documents tab for the movieDetails collection.
{rated: “PG”, awards.nominations: 10}
Problem:
Explore the movieDetails collection that you loaded into your Atlas sandbox cluster and then issue a query to answer the following question. How many movies in the movieDetails collection list “Family” among its genres?
You will find the count() method useful in answering this question using the mongo shell.
Answer:
detailed answer:
You can find this answer in either the mongo shell or in Compass.
In the shell, assuming you’ve loaded movieDetails into the video database and assuming you are connected to your Atlas sandbox cluster, you can issue the following query.
db.movieDetails.find({genres: “Family”}).count()
In Compass you can use the following filter in the Documents tab for the movieDetails collection.
{genres: “Family”}
Problem:
Explore the movieDetails collection that you loaded into your Atlas sandbox cluster and then issue a query to answer the following question. How many movies in the movieDetails collection list “Western” second among its genres?
You will find the count() method useful in answering this question using the mongo shell.
Answer:
detailed answer:
You can find this answer in either the mongo shell or in Compass.
In the shell, assuming you’ve loaded movieDetails into the video database and assuming you are connected to your Atlas sandbox cluster, you can issue the following query.
db.movieDetails.find({“genres.1”: “Western”}).count()
In Compass you can use the following filter in the Documents tab for the movieDetails collection.
{genres.1: “Western”}
Problem:
Suppose you wish to update the value of the plot field for one document in our movieDetails collection to correct a typo. Which of the following update operators and modifiers would you need to use to do this?
Answer:
detailed answer:
As we saw in a couple examples in this chapter, $set is the only operator or modifier required for a simple update operation such as this.
参考:Update Operators