How To Fix Exitcode:100 In Mongod Service: Mongodb
2 min read
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.
Why do we have an exitcode:100 error?
- Incorrect file permission to the required database directory.
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.
- Missing database directory.
You guessed right! When the database directory does not exist.
So, how do we fix this error?
How to fix the
mongod service exitcode:100 error.
- Create a database directory
/data/dbin the root directory if it does not already exist.
sudo mkdir -p /data/db
/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
Now, you can run
mongod in the terminal and start using MongoDB.
Congratulations! You've just got the second error. Progresss :)
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!