MongoDB: A Beginner’s Guide

Learn how to combine the power of Node.js with MongoDB and Mongoose

Bret Cameron
9 min readJun 27, 2019


In the worlds of JavaScript and Node.js, MongoDB has established itself as the go-to database. It is the ‘M’ in the popular MEAN and MERN stacks, and it is generally considered to be more flexible and easier-to-scale than traditional database technologies like MySQL.

But setting a database for the first time can be tricky. When I first experimented with MongoDB, I encountered several frustrating obstacles that made the process much harder than it should have been. In writing this article, I hope you can avoid my mistakes.

The article is split into four parts. We’ll cover how to:

  • Create a cloud database with MongoDB Atlas,
  • Connect to it using Node.js and Mongoose,
  • Create models for our data using Mongoose,
  • Expose API endpoints to perform common database operations.

Even if you’ve never used Node.js or Express before, you should be able to follow along. By the end of the article, you should know the basics of everything necessary to set-up a working MongoDB database.

Part 1: Create a Cloud Database on MongoDB Atlas

MongoDB Atlas is the official cloud database service offered by MongoDB. Though we could set-up an instance of MongoDB locally, getting started with Atlas is much simpler. We’ll be using its free tier.

If you haven’t already, create an account here.

Once you’ve logged in successfully, you should create your first project (feel free to name it whatever you like).

Next, click ‘Build a New Cluster’. You should see a screen like this:

Make sure to choose a region which is labelled ‘Free Tier Available’. Then scroll down and choose the ‘M0 Sandbox’ tier. This is…



Bret Cameron

Writer and developer based in London. On Medium, I write about JavaScript and web development 💻