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
students
collection:
[
{ "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
students
collection for students with a gpa
greater than 3.7.
- Save the results of your query into a new collection named
honor_roll
.
Requirements
- Operate only within the
university
database.
- The
honor_roll
collection should include only students with a GPA greater than 3.7.
- The
students
collection should remain intact with all records.
Hints
- Using
const
to 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 }
]