Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Fall 2022 CS157C CS157C: NoSQL Database Systems

Assignment 2

In this assignment, you will exercise CRUD operations of MongoDB by manipulating data from http://media.mongodb.org/zips.json .

1. Copy and paste results into hw2.txt as instructed.

2. Limit the output to 10 documents.

3. All the tasks should be done on mongosh, not by an application (e.g. a python script).

4. You need to figure out some of the functions required to finish this assignment which include mongoimport command, mapreduce and aggregation functions. I showed the examples of the mapreduce and the aggregation functions in class but you may need to study them further to conduct the given tasks.

Tasks

1. Download the zips.json file to a Docker ubuntu container using the following command.

% wget http://media.mongodb.org/zips.json

2. Import zips.json into MongoDB using mongoimport command. Import the data into a collection called cityinfo in a database called usdata.

3. Show all collections of the database usdata. Copy and paste the command and its result into hw2.txt. (output 1)

4. Find all documents of cityinfo collection. Copy and paste the command and its result into hw2.txt. (output 2)

5. Find all documents with _id that contains 9503 in it. Do not include "loc" in the

output. For example, expected documents in the output may include a document with "_id":"19503" and a document with "_id":"95037". Copy and paste the command and   its result into hw2.txt. (output 3)

6. Use the aggregate function to answer this question. Find all cities with populations     between 23,000 (inclusive) and 150,000 (inclusive) and their state border the Pacific    Ocean ("AK", "HI", "WA", "OR", and "CA" are the states that border the Pacific Ocean). Each line of output should present city first, state next, and then total_population. In   the output, a city should be unique for a given state and it should come with the total population of the city. For example, there should be one line of output for LOS            ANGELES, CA with total population of LOS ANGELES as shown below.

... {"city" : "LOS ANGELES", "state" : "CA", total_pop : ....} ...

Copy and paste the command and its result into hw2.txt. (output 4)

7. Find all zip codes in the cities of San Jose, New York, and Washington (that is, city: "WASHINGTON" and state: "DC") that have a population between 6,000 (inclusive) and 11,000 (inclusive). Copy and paste the command and its result into hw2.txt.    (output 5)

8. Add an embedded document called "Details" into all documents with a Santa Clara    County zip code. In Details, add the following fields with names and values:                {county:"Santa Clara", medianIncome: 93500}. Hint: You may use the readFileSync and split functions on mongosh. Copy and paste the command and its result into hw2.txt. (output 6)

9. Find all documents that have an embedded document named Details without using the zip code. Copy and paste the command and its result into hw2.txt. (output 7)

10. Use a MongoDB mapreduce function to find the population of every state and show the populations in the output. (Ignore the warning about "deprecated".) Copy and   paste the command and its result into hw2.txt. (output 8)

11. Use a MongoDB aggregate function to find the population of every state and show the populations in the output. Copy and paste the command and its result into       hw2.txt. (output 9)

12. Compare the execution times of the mapreduce and the aggregate functions to find the population of every state. Follow the instruction below:

A. Measure the times before and after a call to the mapreduce function, and get      their difference. Copy and paste the command and its result into hw2.txt. (output 10)

B. Measure the times before and after a call to the aggregate function, and get

their difference. Copy and paste the command and its result into hw2.txt. (output 11)

C. Get the executionTimeMillis" from

db.cityinfo.explain("executionStats").aggregate(...) Copy and paste the command and its result into hw2.txt. (output 12)

  Compare A and B. Write your analysis briefly. (output 13)

  Compare B and C. Write your analysis briefly. (output 14)

13. Copy and paste the SSH terminal content after you access an AWS EC2 instance in the AWS Learners Lab using SSH. (output 15) Refer to this video: AWS Learners Lab: To     create an AWS EC2 instance and access it using SSH . Make sure to stop the instance  after taking the information.

Deliverable

Include all the required outputs in hw2.txt. and zip it into hw2.zip. Submit hw2.zip through the submission link on the web cite.