Introduction
You’ve been hired to manage the "Honor Roll" database for a university. The university tracks high-performing students based on their GPA. Your task is to populate the database with student data and identify those who qualify for the Honor Roll, defined as students with a GPA greater than 3.7. You'll store these high achievers in a separate collection called honor_roll.
This challenge will test your ability to insert data, query specific records, and create new collections based on your query results.
Populate and Query the Honor Roll Database
You will insert student data into the students collection and query the top-performing students to populate the honor_roll collection.
Tasks
- Insert the following student records into the
studentscollection:
[
{ "name": "Anna Lee", "age": 19, "major": "Mathematics", "gpa": 3.9 },
{ "name": "Sam Green", "age": 21, "major": "History", "gpa": 3.4 },
{ "name": "Chris Black", "age": 20, "major": "Physics", "gpa": 3.8 },
{ "name": "Jamie White", "age": 22, "major": "Literature", "gpa": 3.5 }
]
- Query the
studentscollection for students with agpagreater than 3.7. - Save the results of your query into a new collection named
honor_roll.
Requirements
- Operate only within the
universitydatabase. - The
honor_rollcollection should include only students with a GPA greater than 3.7. - The
studentscollection should remain intact with all records.
Hints
- Using
constto store the results of your query can help you reference the data later. .toArray()is useful for converting the results of a query into an array for further processing.
Example
After completing the tasks, the honor_roll collection should contain:
[
{ "_id": ObjectId("..."), "name": "Anna Lee", "age": 19, "major": "Mathematics", "gpa": 3.9 },
{ "_id": ObjectId("..."), "name": "Chris Black", "age": 20, "major": "Physics", "gpa": 3.8 }
]
The students collection should still contain all four records:
[
{ "_id": ObjectId("..."), "name": "Anna Lee", "age": 19, "major": "Mathematics", "gpa": 3.9 },
{ "_id": ObjectId("..."), "name": "Sam Green", "age": 21, "major": "History", "gpa": 3.4 },
{ "_id": ObjectId("..."), "name": "Chris Black", "age": 20, "major": "Physics", "gpa": 3.8 },
{ "_id": ObjectId("..."), "name": "Jamie White", "age": 22, "major": "Literature", "gpa": 3.5 }
]
Summary
In this challenge, you acted as the database administrator for a university, tasked with identifying Honor Roll students. You successfully inserted student data into the students collection, queried for high-achievers with a GPA greater than 3.7, and stored these results in a new honor_roll collection. This practical exercise enhanced your understanding of MongoDB commands for inserting, querying, and managing collections effectively.

