From Chapter 2 - REST API, you probably noticed that data is not persisted yet 😢

Everytime we change code, server restarts (via nodemon) and our data is gone 👻

This chapter, we'll move our JSON files to the database so all the CRUD changes from our REST API are persisted.

First things first, you'll need a connection string from MongoDB Atlas. Follow this guide first if you haven't

MongoDB Atlas Signup


SQL databases:

database > tables > rows

(database) data_db
(table) products

           id     name            brand      price
(rows)      1     toilet paper       X       199.99
            2     hand sanitizer     Y       299.99


database > collections > documents

(database) data_db > 
  (collection) products: [  
    (documents)         { "id": 1, "name": "toilet paper", "brand": "X", "price": 199.99, "type": "toiletries" },
                        { "id": 2, "name":"hand sanitizer", "color": "blue", "brand":"Y", "price":299.99 },...

But why noSQL?

For details on the difference, see chapter footnotes