In this activity, you’ll work with asynchronous programming with the Mongoose library, which allows your programs to connect to a MongoDB database.
Overview
The code for this implements a part of the TranscriptService we’ve seen previously in lecture, but using a MongoDB database to store information.
Getting started
Download the starter code and run npm install
. Then run npm run test
; there will be a lot of test failures. The tests fail because getTranscript
doesn’t return the correct result, and because addGrade
isn’t fully implemented. Your first task will be understanding the difference between what getTranscript
should be returning and what it’s actually returning.
Fixing the tests
To complete the task, you’ll need to learn about how Mongoose models work a bit. There are multiple ways to work through this assignment, but the one that matches the structure of the strategy.town Mongoose models uses the .populate()
and .select()
methods to .
- The MongoDB tutorial from the Spring 2025 iteration of this class
- The Population and Field Selection sections of the mongoose guides
- The populate and select parts of the mongoose API docs
- How to Update a model using save(), though as an alternative you could look into how findOneAndUpdate() works
Don’t worry about getting every last one of the tests perfect — the intent of this activity is to practice rapidly trying to absorb new docs while working with a group, and to give you a little bit of exposure to Mongoose models before you have to work with them in IP2. You’ll submit src/service.ts
on Gradescope.