# Setup: MongoDB and Compass

Install MongoDB Community Server and Compass on Windows or macOS, check that the server is running, and connect Compass to it at mongodb://localhost:27017, or use a free Atlas cluster in the cloud instead.

Apprentice · MongoDB · Node.js · Updated November 19, 2026

By Gregor Dzierzon

## After this lesson you can

- Check that a local MongoDB server is running, and start it when it isn't
- Read a MongoDB connection string, such as mongodb://localhost:27017, and tell a local server from an Atlas cluster

## Key takeaways

- MongoDB Community Server is the database itself, and it runs in the background. Compass is the app you look at your data with.
- On Windows, Get-Service MongoDB says whether the server is running. On a Mac, brew services list does.
- mongodb://localhost:27017 means MongoDB on this computer, at its usual port, 27017.
- A free Atlas cluster runs MongoDB in the cloud. Its connection string starts mongodb+srv:// and holds a password, so it never goes in your code.
- The exercises' tests start their own throwaway MongoDB, so you never need a server running to check an exercise.

Before Node can save a single plant, there has to be a MongoDB for it to talk to. Every developer who works on an app with MongoDB sets one up on their own computer first, so they can try things without touching the real data. This lesson does that, once.

## Two pieces: the server and Compass

You'll install two programs:

- **MongoDB Community Server**, the free edition of the database itself. It runs quietly in the background, with no window, waiting for programs to connect, much like the web servers you built in Module 2.
- **MongoDB Compass**, a desktop app for looking at what's in the database: its databases, collections and documents.

Install both from VS Code's terminal. On **Windows** (Windows may ask for permission; click **Yes**):

```bash
winget install MongoDB.Server
winget install MongoDB.Compass.Full
```

On a **Mac**, MongoDB's own Homebrew tap (a list of extra programs) comes first, marked as trusted, then the server (which brings mongosh with it), which you start, then Compass:

```bash
brew tap mongodb/brew
brew trust mongodb/brew
brew update
brew install mongodb-community@9.0
brew services start mongodb-community@9.0
brew install --cask mongodb-compass
```

If a command fails, the same programs are on mongodb.com's download pages: MongoDB Community Server, version 9.0, and Compass. The course uses MongoDB 9.0 and Compass 1.53.

## Is the server running?

On Windows, the installer sets the server up as a **Windows service**: a program Windows starts by itself every time the computer starts. Ask about it by its name, `MongoDB`, in VS Code's terminal (PowerShell):

```bash
Get-Service MongoDB
```

```text
Status   Name               DisplayName
------   ----               -----------
Running  MongoDB            MongoDB Server (MongoDB)
```

`Running` is what you want. If it says `Stopped`, open PowerShell as an administrator (right-click it in the Start menu, **Run as administrator**) and run `Start-Service MongoDB`.

On a Mac, `brew services list` lists the services Homebrew runs. The line for `mongodb-community` should say `started`. If it doesn't, run `brew services start mongodb-community` again.

## Connecting Compass: reading a connection string

Open Compass and start a new connection. Its address box already holds the address of MongoDB on your own computer:

```text
mongodb://localhost:27017
```

That's a **connection string**: everything a program needs to reach a MongoDB server, in one line. Read it in three parts:

- `mongodb://` says what follows is a MongoDB address.
- `localhost` is this computer.
- `27017` is the port, the numbered door MongoDB listens at. 27017 is MongoDB's usual port, the way your Express servers listen at 3100.

Connect, and Compass lists the databases already there: `admin`, `config` and `local`, which MongoDB keeps for itself. Leave those three alone. Your own databases appear beside them as soon as you save something.

![MongoDB Compass connected to mongodb://localhost:27017, listing the three databases MongoDB keeps for itself: admin, config and local](https://www.ask-codey.com/lessons/TODO)

## Or: a free Atlas cluster

**MongoDB Atlas** runs MongoDB for you in the cloud. Pick it if you can't install programs on your computer, or if you'd like your data reachable from anywhere. Module 6 uses Atlas to put an API online, and walks through it screen by screen.

On mongodb.com, sign up for Atlas and create a cluster. Choose the **Free** option: the other choices are paid. Then add a database user with a password, allow your computer's address, and copy the connection string Atlas gives you. It looks like this, with your own names in place of the ones in angle brackets:

```text
mongodb+srv://<user>:<password>@<cluster-name>.mongodb.net/
```

`mongodb+srv://` means "look up this cluster's servers by its name", and the part before the `@` is your user and password. A string with a password in it never goes in your code, or in Git. The next lesson keeps it in a `.env` file, where it stays out of both. Compass connects to it the same way: paste it into the address box.

## The exercises bring their own MongoDB

The exercises in this course never use your MongoDB. Their tests start a **throwaway MongoDB** of their own with a package called mongodb-memory-server, load the data they need, and stop it when they finish, so your own databases are never touched.

If MongoDB is installed on your computer, the tests use it. If it isn't (with Atlas, say), the first `npm test` downloads MongoDB for the tests: **about 950 MB on Windows, and about 180 MB on a Mac**. It's downloaded once per computer and kept for every exercise after that, so plan the first run for a fast connection.

## Check yourself

2 questions to try on the lesson page.

## So what

A MongoDB of your own, and Compass to look inside it, is where every database idea in this course gets tried first, safely, away from anyone's real data.

## Key terms

- [MongoDB Compass](https://www.ask-codey.com/glossary/mongodb-compass)
- [MongoDB Atlas](https://www.ask-codey.com/glossary/mongodb-atlas)
- [Connection String](https://www.ask-codey.com/glossary/connection-string-mongodb)
- [Windows Service](https://www.ask-codey.com/glossary/windows-service)
- [Homebrew](https://www.ask-codey.com/glossary/homebrew)

## Related

- [Documents and Collections](https://www.ask-codey.com/lessons/node-mongodb-documents-and-collections)
- [Connecting from Node and Saving Documents](https://www.ask-codey.com/lessons/node-mongodb-connect-and-insert)

Source: https://www.ask-codey.com/lessons/node-mongodb-setup
