Question: ASSIGNMENT 4 Due Date: December 3, 2023 (11:59 pm) In this assignment, you will use MongoDB query language to read, process, and extract data




ASSIGNMENT 4 Due Date: December 3, 2023 (11:59 pm) In this assignment, you will use MongoDB query language to read, process, and extract data from MongoDB collections. The first part of the assignment involves writing "simple MongoDB queries" using the find() method. The second part of the assignment involves writing "advanced MongoDB queries" using the MongoDB aggregation pipeline. For each question, your answer should be a single MongoDB statement (i.e., there should be a piece of code starting with db.collection.method() and ending with a semi-column). Save your answers to a text file. Do NOT forget to write your group number and the names of all the members in your group at the top the file using comment lines (/* Group x*/) (/* Member 1 Name*/) (/* Member 2 Name*/) Use a comment line to indicate which question the subsequent query answers (such as /*Answer to Question X*/). Submit a soft copy of your assignment (one submission per group) by the due date (refer to the class syllabus for late submission penalties). You can make only ONE attempt. Therefore, do NOT submit your assignment prematurely if you think that you can make changes on your solution later. Good luck! Part 1: Writing Simple MongoDB Queries We have a collection of researchers named "scientists" (see the scientists.json file). This collection keeps track of basic information about researchers, like their name, birth date, death date (if any), contributions to the scientific world, awards received for their contributions. Each document has a unique_id field and looks like this: { _id: 1, name: { first "John", last "Backus" }, birth ISODate("1924-12-03T05:00:00Z"), death ISODate("2007-03-17T04:00:00Z"), contribs [ ] "Fortran", "ALGOL", "FP" ], awards [ { { award: "W.W. McDowell Award", year: 1967. by "IEEE Computer Society" award "National Medal of Science", year: 1975, by: "National Science Foundation" award "Turing Award", 1977, year by : "ACM" } 1. Find the list of researchers who were born before 1935? 2. Find the list of researchers who have received the "National Medal of Science" award since 1970. 3. Display only the last name and the first two contributions of all scientists. Sort the list in ascending order by the last name. 4. Find the list of researchers who are still alive. Limit the result set to 3 researchers. 5. Find all researchers who have made contributions to both "Fortran" and "Java". Part 2: Writing Advanced MongoDB Queries We have a collection of populations by postal code named "codes" (see the codes.json file). The postal codes are in the_id field, and are therefore unique. Documents look like this: { _id: "35045", city: "CLANTON", loc [-86.64, 32.84], pop: 13990, state : "AL" } Note that there are 50 non-overlapping states in the US with two letter abbreviations such as NY and CA. In addition, the capital of Washington is within an area designated the District of Columbia, and carries the abbreviation DC. For purposes of the mail, the postal service considers DC to be a "state." So in this dataset, there are 51 states. A city may overlap several postal codes. Write an aggregation query to answer the following questions. in the result set is used a placeholder for the correct answer. 6. Find the population of each state. The output should look like this: { { }, _id: "CA", population 7. Find the population of the postal code in each state with the highest population. The output should look like this: { }, _id: "MT", population state : "WI", population state "WV", population 8. Find the population of each city in the state of New York (NY) and list the postal codes that are included in each city. The output should look like this: { _id = "ELMIRA", population postal codes: [ ] population of ELMIRA>, } , , _id: "WHITESVILLE", population : , postal codes: [ ] 9. Find the largest city in each state. The output should look like this: { _id: "WI", city: , population _id: "VT", city: , population }, 10. Calculate the average population of cities in California (CA) and New York (NY) with populations over 30,000. The output should look like this: { pop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
