# 4:Mutating (changing) a Database

We cover a lot in this tutorial. As such, I do not suggest you complete it in one sitting.

This tutorial closes the loop of database operations: I show you how to create, update and delete rooms. Furthermore, I explore some advanced array operations that allow us to filter data elegantly.

Before you start the tutorial, follow the getting started steps below

As this is a fairly long tutorial, I've broken it down into chunks.

# Part 1: Overview (everyone should watch this)

In this part of the tutorial, I look at how we can use JavaScript array filtering to get the room filter working. This is fairly advanced; however, it shows off the power of JavaScript.

# Part 3: Mutating a Database (everyone should watch this)

In this part of the tutorial, I look how we can change the values in a database.

# Getting Started

  • git clone --branch tutorial-4-starter-code https://github.com/joeappleton18/solent-room-finder.git tutorial-4
  • Navigate into the tutorial-4 folder
  • Install the dependencies: npm install

# Setting up the database

  • Get the connection string of your MongoDB server.In the case of MongoDB Atlas, it should be a string like this (notice how we've added rooms as the database name):

mongodb+srv://<username>:<password>@my-project-abc123.mongodb.net/rooms?retryWrites=true&w=majority

  • If you are running MongoDB locally, it will look something like this:

mongodb://127.0.0.1:27017/rooms

  • Copy the .env.local.example file in this directory to .env.local, which will be ignored by Git)

    • Set your MONGODB_URI with the the MongoDB connection string.
  • Open http://localhost:3000 (opens new window) with your browser to see the result.

  • Run the development server: npm run dev

  • Check everything is working by running our tests: npm run cypress:run