CS396: Spring 2021

Intro to Web Development

CS396: Spring 2021

Assignments > Lab 3. Practice with MongoDB and Promises

Due on Fri, 04/16 @ 11:59PM. 5 Points.

In today’s lab, you’re going to get some practice querying MongoDB using Mongoose and Express.

Download & configure the Lab 3 files

lab03.zip

  1. Download lab03.zip and unzip it.
  2. Copy your .env file you created last week into lab03.
  3. Run the installation: npm install
  4. Populate your database: npm run populate
  5. Take a look at your database using the MongoDB cluster on mongodb.com. You can view your data in the collections tab of the cluster. Your new database should be called lab03.
  6. Run your web server: npm start
  7. Check your endpoints:

Some suggestions

A few tips before you begin:

Your Tasks

Open the lab03 folder in VS Code, and complete the following tasks.

1. POST /artists

Implement the POST method for the http://localhost:8081/artists endpoint.

2. GET /artists/:id

Implement the GET method for the http://localhost:8081/artists endpoint.

For the response:

3. DELETE /artists/:id

Implement the DELETE method for the http://localhost:8081/artists endpoint.

For the response:

4. PATCH /artists/:id

Implement the PATCH method for the http://localhost:8081/artists endpoint. You will update only the fields that match the fields in the request body. If a field is not present in the request body, leave it untouched in the artist object.

For the response

Implement a GET method for the http://localhost:8081/search endpoint, which should be a general-purpose search endpoint to query for either tracks or artists based on a term keyword. This endpoint should have two required query string parameters:

Some valid URL queries are shown below (linked to the “solutions” deployment so that you can test it out):

If you have time:

Submit to Canvas

When you’re done, please submit your zipped routes.js file to Canvas (e.g. routes.js.zip).