Yaşar Ateş

System and Security Administration Manager02 August

Strapi Project with MongoDB

If you don’t want keep the contents linked to your project at the relational data base, you can use the Strapi that is easy to use and open sourced app. In this article, we’re going to be reviewing the topich of how a Strapi project are created, how the project that was created integrate with MongoDB.

Creating a Strapi Project

To create the Strapi project first the Node.js and Npm needs to be installed on your computer. If it’s not you can install the Node.js here, and Npm here.

After you completed the installations reach to directory in which you will create your project from command prompt screen. Run the following command in directory.

Step1

After the installation of project has been completed, a screen that allows you to create an admin user like below will open automatically.

Step2

 

You need not to lose the information you will login by this screen. When you stopped the project and start it up again you can login to your project with this information. After you entered the admin information you can reach the panel that allows you to create your contents in your project.

Step3

 

Your Strapi project is all ready for creating content. However the project use SQLite as default database. Before starting to create a project, let’s make the MongoDB integration.

Creating the MongoDB integration

In order to provide MongoDB integration, let’s first review files of the Strapi project we created.

Step4

 

There are contents under the project in which we will create our project in directory of api. And in the config directory there are configuration files belong to the project for all environments.

Reach the files that database information are kept for MongoDB integration. For this follow the path config>environments>development. Open the database.json here. We see that SQLite information are kept in the current file. Change the connection information to MongoDB like below.

Step5

 

After changing the config file the command prompt will begin receiving error. The reason of this some of MongoDB requirements are missing. To complete the requirements run the following command.

Step6

 

Step7

 

After running the command we have performed the MongoDB integration. However to start up our project database in the config file needs to be created on MongoDB. For this, connect to 27017 port on MongoDB Compass Community.

Step8

 

After connecting create a new database named “strapi”. While creating the database we can name the collection as default.

Step9

 

After creating the database we can start up our Strapi project. For this, run the following command in project directory.

Step10

 

When the project has started up it is going to want you to create admin user again. Create the admin user with the same information. After creating the admin user we can begin to create contents belong to our project.

Therefore we created a Strapi project, provided the MongoDB integration of this project. I hope it was helpful.

Kategoriler