Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB

Where Are We Storing Stuff?

Before we code our full-stack MERN (MongoDB, Express, React, and Node.js) application, we need a place to store our data. The best way to do this is to set up a MongoDB instance. We’ll run MongoDB inside a Docker …


This content originally appeared on DEV Community and was authored by Jay Watson

Where Are We Storing Stuff?

Before we code our full-stack MERN (MongoDB, Express, React, and Node.js) application, we need a place to store our data. The best way to do this is to set up a MongoDB instance. We’ll run MongoDB inside a Docker container to keep things simple and easily manageable.

Setting Up MongoDB with Docker

We'll use the official MongoDB image from Docker Hub. To pull and run the MongoDB container, execute the following command in your terminal:

`docker run -d --name mongodb -p 27000:27017 \
  -e MONGO_INITDB_ROOT_USERNAME=watson \
  -e MONGO_INITDB_ROOT_PASSWORD=watson mongo`

Let's break this down:

  • docker run -d runs the container in detached mode (in the background).
  • --name mongodb names the container "mongodb" for easy reference.
  • -p 27000:27017 maps port 27000 on your local machine to MongoDB's default port 27017.
  • -e MONGO_INITDB_ROOT_USERNAME=watson sets the MongoDB root username to "watson".
  • -e MONGO_INITDB_ROOT_PASSWORD=watson sets the password to "watson".
  • mongo specifies the image to use (Docker will pull it if it’s not already available locally).
  • Once this command runs successfully, you’ll have a MongoDB instance up and running in a Docker container!

Connecting to MongoDB

Now that we have our MongoDB instance running, we need a way to interact with it. One of the best tools for this is Studio 3T for MongoDB. It provides an intuitive UI to visualize and manage your database.

To connect Studio 3T to your MongoDB instance:

  • Download and install Studio 3T (there’s a free tier that works great).
  • Open the application and create a New Connection.
  • Create a new connection
  • Past the connection string into the connection as follows: mongodb://watson:watson@localhost:27000/ Connect to a Mongo DB
  • Click Test Connection to ensure everything works.

Test the connection

  • Save and connect!

What's Next?

With our database set up, we’re ready to start building the backend of our application using Express.js. In the next part of this series, we’ll:

Set up a Node.js server

Connect it to our MongoDB database

Create our first API endpoints

Stay tuned for Part 2: Building the Backend with Express.js!


This content originally appeared on DEV Community and was authored by Jay Watson


Print Share Comment Cite Upload Translate Updates
APA

Jay Watson | Sciencx (2025-03-09T01:22:07+00:00) Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB. Retrieved from https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/

MLA
" » Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB." Jay Watson | Sciencx - Sunday March 9, 2025, https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/
HARVARD
Jay Watson | Sciencx Sunday March 9, 2025 » Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB., viewed ,<https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/>
VANCOUVER
Jay Watson | Sciencx - » Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/
CHICAGO
" » Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB." Jay Watson | Sciencx - Accessed . https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/
IEEE
" » Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB." Jay Watson | Sciencx [Online]. Available: https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/. [Accessed: ]
rf:citation
» Let’s Build a Full-Stack App Using the MERN Stack! Part 1: Mongo DB | Jay Watson | Sciencx | https://www.scien.cx/2025/03/09/lets-build-a-full-stack-app-using-the-mern-stack-part-1-mongo-db/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.