Backend API Development | Internships | Node Js

Strapi : Id-Card-Repository

Hi! Today I am going to create a new project in Strapi, called id-card-repository. The database, which will be used for this project is MongoDB.

Prerequisites :

However, before starting to create the project, I have to make sure that the MongoDB version is 3.6 or above.

To check MongoDB version, open the terminal then type :

$ mongo --version

If you have not installed MongoDB yet, you can see the Strapi documentation here to install MongoDB. This goes to Windows, MacOS, and Ubuntu 18.04+ users.

Now make sure that you have MongoDB running in the background. This can be known by typing this in terminal :

$ service mongod status

—- So, Let’s Start ! —-

First, I will create a new Strapi project named id-card-repository. This can be created by typing this on terminal :

$ yarn create strapi-app id-card-repository

Warning :We are not going to start with `… --quickstart ` as it will configure the database management system to SQLite.

I was asked to choose the installation type. I chose “Custom (manual settings)” to be able to configure some settings.

MongoDB configuration on Strapi

Then, set the default database client to “mongo”.

After that, follow this configuration, as stated in Strapi Documentation here.

Eventually, you will be prompted like below if the application was successfully created.

Nice! We have successfully configured MongoDB on Strapi. This is optional but if I open database.js inside the id-card-repository folder in vscode, the connector is set to `mongoose` which indicates successful configuration.

Then change the directory to the folder of application :

$ cd id-card-repository

Run Strapi application :

$ yarn develop

After this, we will be automatically directed to registration page :

Just fill in and then click the Ready to Start button. Then we will be in admin dashboard page.

Click the “CREATE YOUR FIRST CONTENT-TYPE” button then create the content-type named “id-card-repository”. Then click continue.

Eventually,  we are going to create fields, based on this schema.

const User = new Schema({
nik: { type: String },
name: { type: String },
birthPlace: { type: String },
birthDate: { type: Date },
sex: {
type: String,
bloodType: {
type: String,
enum: [‘A’, ‘B’,’O’,’AB’]
address: [{
rt: Int,
rw: Int,
kelDesa: String,
kec : String
religion: { type: String },
marriageStatus: {
type: String,
enum: [‘KAWIN’, ‘BELUM KAWIN’]
occupation: { type: String },
nationality: {
type: String,
enum: [‘WNI’, ‘WNA’]
expDate: { type: Date },
picture: {
profilePicture: { data: Buffer, contentType: String },
cardPicture: { data: Buffer, contentType: String },
withPersonPicture: { data: Buffer, contentType: String },
issuedProvince: { type: String },
issuedCity: { type:String },
issuedDate: { type: Date }

Some fields need advanced configuration (not advanced settings). For example, sex field, is enum. Then we have to set the values to ‘LAKILAKI’ and ‘PEREMPUAN’.

For the picture field, on the ‘Select allowed types of media’, choose Images so users can only upload images to the field.

Even though some fields have not been created yet, it can be added later. Last, click the Save button on the top right side of the page.

Do not forget to install the GraphQL plugin on the Marketplace bar on the left side of the page. If it was downloaded successfully, it shows ‘Already Installed’ on the ‘Download’ button.

This GraphQL plugin must be installed as we will be using GraphQL API in Strapi.

On the Roles & Permissions tab, we should add Manager role, by clicking the ‘+Add New Role’ button. Then set permissions like below :

The development will be continued to the next part. Thank you very much for reading!

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *