How To Fix Exitcode:100 In Mongod Service: Mongodb

Software Engineer | Technical Writer
Search for a command to run...

Software Engineer | Technical Writer
No comments yet. Be the first to comment.
Identity and Authentication in a Kubernetes Cluster.
A guide to understanding common terminal operations that occur during the installation of a Linux application.

An implementation of lazy loading in Reactjs with React router v6.

A beginner-friendly guide to linking pages in Reactjs

If you're trying to configure MongoDB on your Ubuntu 20.04, one of the problems you might encounter is working with the mongod service. This article explains how to fix the exitcode:100 error and why it pops up when you try to start a mongod service for the first time on Ubuntu.
However, before I explain how to fix this, how about we look into why the error exists in the first place? Meanwhile, If you're not interested in learning about the 'why', you can skip this part.
This happens when the file permission assigned to the database directory does not have the required permissions for operations e.g write and permissions for certain users. The database directory is the directory MongoDB communicates with while performing read and write operations.
You guessed right! When the database directory does not exist.
So, how do we fix this error?
mongod service exitcode:100 error./data/db in the root directory if it does not already exist.cd ~
sudo mkdir -p /data/db
The /data/db directory is the database directory MongoDB uses for all database operations. This explains why mongod has to connect to it first before any form of operation can take place between MongoDB and your computer.
Note: This operation requires admin privileges, so it is important that we use the
sudocommand.
Now, you can run mongod in the terminal and start using MongoDB.

Congratulations! You've just got the second error. Progresss :)
The mongod service would fail on this attempt because it needs a write permission to create a lock file. Without a doubt, the next thing to do is give write permission to all users. In this case, we'd use a wildcard(a word I coined for this command) to give all users read, write, and execute permission.
From the root directory,
sudo chmod 777 /data/db
You can read up on linux file permission here.
Now, you can run mongod and use MongoDB.
Meanwhile, if you found this useful, feel free to let me know in the comment section or anywhere you feel appropriate :)
See you around!