Lab 3 - MongoDB CRUD and Javascript

Submit a PDF file to Canvas with the answers to the following questions. No other format will be accepted.

Use the zip codes dataset for this homework. Use your browser to save it to a file.

Part 1: 3 points each

  1. What is the primary schema represented in the zipcodes.json file? Explain it fully.

    Show the MongoDB query OR python code snippet you would use to answer questions 2 through 10 AND show the result of that query or snippet.

  2. Get the zipcodes.json file loaded into a db on your machine (local) or Atlas (cloud).
  3. Count the number of zip codes in the collection.
  4. Count the total number of zip codes in the New England states (CT, RI, MA, VT, NH, and ME).
  5. Determine the total population of Rhode Island.
  6. Determine which zipcode has the smallest population.
  7. Determine the southernmost zipcode in the database.
  8. Determine average population of states beginning with ‘M’.
  9. Which zip codes have more than 50,000 population.
  10. Which city has the most zip codes? Hint1: include the state in case the city name isn’t unique across the states. Hint2: be sure to handle the possibility of a tie.

Part 2: 5 points each

  1. Display the zip codes in Louisiana (LA) sorted by population from largest to smallest.

  2. Provide a python or javascript code snippet that will determine which state has the fewest zip codes. It is not necessary to provide a complete working program.

  3. Write a javascript code snippet suitable for running in the mongo shell that will generate a new database collection of 100 random credit card charge amounts with the following schema. It is not necessary to provide a complete working program.

     {
     cardNo : 12 character string,
     expDate: {mm: integer, yy: integer},
     amount: float with 2 decimal places,
     secCode: integer
     }
    
  4. What MongoDB statement(s) would you use to add a four-digit integer field named “plusFour” initialized to “0000” to each entry of the zipcode collection?

Extra Credit: Up to 5 points

Provide a python program that will use the zips MongoDB database (and no other data or source) to determine which zipcode is nearest the center of the continental United States (that is, considering only zipcodes in the states other than AK and HI). Looking up the answer and simply hardcoding it in your code is unacceptable.