Local Strapi + cloud MongoDB Atlas

Deepa Varma
3 min readMar 9, 2020

--

Exploring how they can be connected

Strapi is “The open source Headless CMS Front-End Developers love.” And MongoDB Atlas is the cloud version of mongo db and is “Built for agile teams who’d rather spend time building apps than managing databases.”. I wanted to make use of both in my application.

My problem was that I did not want to install Strapi globally or with their — quickstart option which automatically connected to SQLite. Plus, I did not want to install MongoDB locally on my machine.

The task at hand is to connect Strapi installed locally in my project folder with my online free account on MongoDB Atlas.

  1. Opening a MongoDB atlas

Opening a Mongo DB atlas account is straightforward. Step 1 is to create an account. Once logged in, create a new user with user name and password. Remember to save this username and password. Because it is needed while setting up Strapi. Set up the cluster. In the Cloud Provider and Region, select a free tier option to host the account. Cluster tier is M0 for a free account. MondgoDB version is automatically selected. Give a name to the cluster.

Once the cluster window opens up, click the ‘Connect’ button. Use the ‘Connect your Application’ option. From the connection string, select the host name which is the part of the string after @ and until …..net’. In my case, it is ‘myproject-fcvyt.mongodb.net’. Back to the application.

2. Setting up Strapi locally

Open up the terminal with the project root folder. Run Strapi installation command as per their documentation. However, do so without the ‘ — quickstart’ option because this installs a default connection to SQLite, which is not the purpose. The folder name can be anything. This creates a new Strapi application inside the project root folder.

npx create-strapi-app my-strapi

There are a few setup questions. This article from their official documentation explains it. However, the options to be chosen are different from the documentation. Use the keyboard arrow keys to move the cursor. Hit Enter after each choice.

? Choose your installation type
Custom (manual settings)Choose your installation type Custom (manual settings)
? Choose your main database:
SQLite
Mongo
MySQL
Postgres
? Database name: (my-strapi) (shows project name by default; hit
enter)
? Host: myproject-fcvyt.mongodb.net
? +srv connection: true
? Port (It will be ignored if you enable +srv): 27017 (do nothing;
simply hit enter)

? Username:<mongodb atlas cluster username>
? Password:<mongodb atlas cluster password>
? Authentication database (Maybe "admin" or blank): (leave blank hit
enter)

? Enable SSL connection: true

The next step is critical for the cms admin panel to be set up. Change into the strapi folder, which in this case is my_strapi

Change directory:
$ cd my-strapi
Start application:
$ npm run develop

The admin panel opens up. Enter a username and password as administrator.

Here this challenge and this story ends.

Thanks for reading.

--

--

Deepa Varma

Reviving interests midway through life: writing, coding full stack, watercolour and digital art. My website in React: https://deepavarma.com