Strapi blog logo
  • Product

      Why Strapi?Content ArchitectureRoadmapIntegrationsTry live demo
      OverviewContent Types BuilderCustomizable APIMedia LibraryRoles & Permissions
      Discover Strapi Enterprise EditionDiscover our partners
  • Pricing

  • Solutions

      Static WebsitesMobile ApplicationsCorporate websitesEditorial SitesEcommerce
      Delivery HeroL'EquipeSociete GeneralePixelDustBanco International
      Discover all our user stories
  • Community

      CommunityWrite for the communityWall of LoveStrapi Conf 2021
      SlackGitHubYoutubeCommunity Forum
      Meet the Strapi Community StarsDiscover the Strapi Showcase
  • Resources

      BlogStartersNewsroomSupport
      Strapi AcademyTutorialsVideos GuidesWebinars
      The Guide to Headless CMS Strapi Community Forum
  • Docs

      Getting StartedContent APIConfigurationInstallationDeploymentMigration
      Getting StartedContent ManagerContent-Types BuilderUsers, Roles & PermissionsPlugins
      Developer DocumentationStrapi User Guide

Looking for our logo ?

Logo Brand download
Download Logo Pack
See more Strapi assets
Strapi blog logo
  • Product

    Product

    • Why Strapi?
    • Content Architecture
    • Roadmap
    • Integrations
    • Try live demo

    Features

    • Overview
    • Content Types Builder
    • Customizable API
    • Media Library
    • Roles & Permissions
    • Discover Strapi Enterprise Edition
    • Discover our partners
    Features cover

    Unlock the full potential of content management

    See all features
    Strapi Enterprise Edition

    Discover the advanced features included in Strapi Enterprise Edition.

    Get Started
  • Pricing
  • Solutions

    Solutions

    • Static Websites
    • Mobile Applications
    • Corporate websites
    • Editorial Sites
    • Ecommerce

    Stories

    • Delivery Hero
    • L'Equipe
    • Societe Generale
    • PixelDust
    • Banco International
    • Discover all our user stories
    Delivery Hero team

    Delivery Hero manages their partner portal with Strapi.

    Read their story
    turn 10 studios website

    How 1minus1 delivered a creative website for Turn10 Studios 25% faster with Strapi

    Discover their story
  • Community

    Community

    • Community
    • Write for the community
    • Wall of Love
    • Strapi Conf 2021

    Resources

    • Slack
    • GitHub
    • Youtube
    • Community Forum
    • Meet the Strapi Community Stars
    • Discover the Strapi Showcase
    Strapi Conf

    The first Strapi Global User Conference.

    Register now
    Write for the community

    Contribute on educational content for the community

    Discover the program
  • Resources

    Resources

    • Blog
    • Starters
    • Newsroom
    • Support

    Learning

    • Strapi Academy
    • Tutorials
    • Videos Guides
    • Webinars
    • The Guide to Headless CMS
    • Strapi Community Forum
    Introducing Strapi Academy

    Everything you need to know to master Strapi.

    Go to the academy
    Strapi Repository on GitHub

    Get started with the Strapi repository

    Go to repository
  • Docs

    Developers

    • Getting Started
    • Content API
    • Configuration
    • Installation
    • Deployment
    • Migration

    User Guide

    • Getting Started
    • Content Manager
    • Content-Types Builder
    • Users, Roles & Permissions
    • Plugins
    • Developer Documentation
    • Strapi User Guide
    Install Strapi

    Install Strapi locally or wherever you need.

    Get Started
    Migration Guides Strapi

    Using a previous version of Strapi? Migrate to the latest.

    Read Guides
Get Started
Back to articles

Using mLab with Strapi

using-mlab-with-strapi
  • Share on facebook
  • Share on linkedin
  • Share on twitter
  • Share by email
Pierre Burgy

Pierre Burgy

What is Strapi?

Strapi is a Node.js Content Management Framework which makes API creation easier. Halfway between a Node.js Framework and a Headless CMS, it has been designed to build APIs in seconds instead of weeks thanks to its built-in features: Admin Panel, Authentication & Permissions management, Content Management, API Generator, etc.

Strapi mLab

APIs built with Strapi need a database to store data. The default database management system is MongoDB. Obviously, you can use a MongoDB instance running on your own computer but, if you need to collaborate with other developers, or simply do not want to install MongoDB on your computer, you will probably want to setup a database on a server and use it remotely.

What is mLab?

Database management is hard. Even more harder than apps', you have to deal with highly important challenges, such as security, scalability and performances. To make developer's life easier, some companies decided to offer a new concept: Database as a Service (DBaaS). They all provide fully hosted databases access, so you can focus on your code without spending time on your database's infrastructure.

Tens of online DBaaS exist: Compose.io, MongoDB Atlas, etc. One of the first in the MongoDB as a Service market is mLab which is also one of the easiest to use. Its free plan lets you try it without having to enter your credit card informations. For all these reasons, we decided to explain you how to use mLab with Strapi.

First of all, we are going to setup the mLab database. Then, we will generate a brand new Strapi API connected to this database.

mLab database setup

Let's start with the mLab database!

Register

mLab is an online service, so, except if you already have an account, you need to create one.

Visit the register page, fill in the form and submit it.

Strapi mLab

Validate your email address

To complete the registration process, validate your email address by clicking on the link in the email you received from mLab.

Strapi mLab

Well done, your email has been validated. Let's make the magic happen!

Create a database

To create a new database, click on the "Create new" button at the right of "MongoDB deployments".

Strapi mLab

The database can be hosted on Amazon Web Services, Google Cloud Platform or even Microsoft Azure. In this example, we are going to use AWS with a "Sandbox" database:

Strapi mLab

The closer your API is hosted to your database, the faster it will be. If you plan to use the database for production, it is best to host your database and API servers in the same cloud provider and region. If that's not possible, select the region closest to your API servers:

Strapi mLab

Your database needs a name. Give it one, ideally according to the name of your project:

Strapi mLab

Note: we recommend you to suffix the database's name with your current environment (eg. myproject-development or myproject-production).

The Order Confirmation page gives you a summary of your choices. If everything is correct, click on "Submit Order":

Strapi mLab

Easy-peasy: your database is created!

Strapi mLab

Create a user

You are almost done. The only thing you need is a user in order to be able to connect to the database.

Click on the "Users" tab, then on "Add database a user":

Strapi mLab

A popup should appear. Choose a username and a password for your database user (do not forget these credentials, you will need them later):

Strapi mLab

Here we are, the user has been created:

Strapi mLab

On the screen above you can see the line which should be used "To connect using the mongo shell": mongo ds125048.mlab.com:25048/myapp-development -u <dbuser> -p <dbpassword>.

In this line, three informations are going to be useful for the next section of the tutorial:

  • Host: ds125048.mlab.com
  • Port: 25048
  • Database: myapp-development

Congrats, you successfully set up a database and added a user!

Create a Strapi app

You are now able to use your brand new database from a Strapi project.

Install Strapi

Requirements: please make sure Node 8 (or higher) is installed on your machine.

Install Strapi using npm:

$ npm i strapi@alpha -g

Generate a new Strapi project

To create a new project, simply run the following command:

$ strapi new my-app

This is the most important part: answer the questions with the informations provided by mLab.

⚠️ UPDATE: in latest version of Strapi you will have to set the config value: Authentication database the value has to be the database name.

Strapi mLab

This actually generates a new Strapi project and writes the configurations you specified in a file located at my-app/config/environment/development/database.json:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-mongoose",
      "settings": {
        "client": "mongo",
        "host": "ds125048.mlab.com",
        "port": "25048",
        "database": "myapp-development",
        "username": "myusername",
        "password": "mypassword"
      },
      "options": {
        "authenticationDatabase": "myapp-development",
        "ssl": false
      }
    }
  }
}

Note: a similar file containing the production settings exists (path: config/environments/production/database.json)

Start your server

Enter in your project's directory and start the server:

$ cd my-app
$ strapi start

Strapi mLab

Register your first user

From now, the Strapi admin panel should be at the following URL: http://localhost:1337/admin.

Register your first user to double check that your database is correctly connected:

Strapi mLab

At this point, you should see in mLab the first collections created by Strapi:

Strapi mLab

Update Database Settings

Later, or because you are already working on a Strapi project, you may want to update your database credentials.

To do so, please use the Settings Manager:

Strapi mLab

Note: you can also directly edit files (config/environments/development/database.json and config/environments/production/database.json).

Conclusion

Congratulations! You successfully configured a mLab database and generated a new Strapi project using it.

When you are going to production, we strongly recommend you to create another database to separate development and production data. Also, Sandbox plan (free) is great for development but is not adapted when your API is live.

We hope this tutorial has been useful for you. Please comment it to give a feedback and share your opinion about DBaaS solutions.

  • Share on facebook
  • Share on linkedin
  • Share on twitter
  • Share by email
Adding Webhooks in Strapi 🎯
  • Product

Adding Webhooks in Strapi 🎯

Webhooks are already implemented on your favorite headless CMS by now.

Pierre Burgy

Pierre Burgy

October 31, 2018

Why we split the management of Admin Users and End Users
  • Product

Why we split the management of Admin Users and End Users

Strapi wants to reinvent the way content is written and distributed to people. Separating the Admin User from the End User is just one step towards fulfilling the promise of a headless CMS.

David Kartuzinski

David Kartuzinski

July 16, 2019

Webhooks explained and how to use them in Strapi
  • Product

Webhooks explained and how to use them in Strapi

Webhooks are automated messages that are sent each time an event happens. Let's get you hooked on it (pun intended).

Yves

Yves Do

January 22, 2020

Unleash content.

Read the docs
Get Started

Strapi is the most popular open-source Headless CMS. Strapi gives developers the freedom to use their favorite tools and frameworks while allowing editors to easily manage their content and distribute it anywhere.

Product

  • Why Strapi?
  • Content Architecture
  • Features
  • Enterprise Edition
  • Partner Program
  • Roadmap
  • Support
  • Integrations
  • Try live demo

Resources

  • How to get started
  • Meet the community
  • Tutorials
  • API documentation
  • GitHub repository
  • Starters
  • Strapi vs Wordpress
  • The Guide to headless CMS

Integrations

  • Gatsby CMS
  • React CMS
  • Vue.js CMS
  • Nuxt.js CMS
  • Next.js CMS
  • Angular CMS
  • Gridsome CMS
  • Jekyll CMS
  • 11ty CMS
  • Svelte CMS
  • Sapper CMS
  • Ruby CMS
  • Python CMS

Company

  • About us
  • Blog
  • Careers
  • Contact
  • Newsroom
  • © 2021, Strapi
  • LicenseTermsPrivacy