Database Setup

Connect your ZapStart application to MongoDB Atlas for reliable, scalable data storage.

Introduction

ZapStart uses MongoDB for data storage. MongoDB is a document database that makes it easy to store, query, and index your application data. In this guide, we'll set up MongoDB Atlas, a fully-managed cloud database service.

MongoDB Atlas offers a free tier that's perfect for development and small projects. You can upgrade as your needs grow.

Setting Up MongoDB Atlas

Let's create a MongoDB Atlas account and project:

  1. Go to MongoDB Atlas and create an account (or sign in)
  2. Choose the free tier, region could be N. Virginia (us-east-1) or any other region.
  3. Create a user database and save the username and password somewhere safe.
  4. Click on connect or choose a connection method, choose Drivers and then Node.js
  5. Copy the connection string to your .env file MONGODB_URI=, it would look something like this:
    mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
  6. Replace the username and password with your database user's username and password.

Choose a descriptive name for your project to help you identify it later, especially if you plan to build multiple applications.

Configure Network Access

  1. Go to Network Access in the left menu
  2. Click Add IP Address
  3. For development, select Allow Access from Anywhere (0.0.0.0/0), this allows you to connect to the database from your local computer or from production servers.
  4. Click Confirm

Keep your database credentials secure! Don't commit them to version control or share them publicly.

Changing the Database Name

By default, MongoDB will use a database named "test". You should change this to a name that reflects your application.

To do this, modify the URI to include your database name before the query parameters:

mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority

Notice how we added /my-awesome-saas before the ? in the URI. This tells MongoDB to use a database named "my-awesome-saas".

For a quick tutorial on database in zapstart, please see the MongoDB Tutorial after setting up your database.

Next Steps

Now that you've configured your JWT secrets and MongoDB, you can continue setting up the rest: