šŸ³ļøā€šŸŒˆ Happy Pride month!

MongoDB on Linux - Data directory /data/db not found

by Matt Fantinel
09 Jun 2019 - 1 min read

When setting up a Linux server or development machine, you might need to install MongoDB. However, every single time I've stumbled upon an error right when trying to start the mongod service, after following the official instructions. The important line here is:

exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating

This seems like an error on Mongo's install script. The problem is that by default, Mongo points to that /data/db folder, and it either forgets to create or set ownership of it on installation.

Thankfully, the solution is quite simple. First, we'll make sure that the folder in question exists. Run the following command from your Terminal:

shell
sudo mkdir -p /data/db/

And then, we'll set the ownership of the folder to the user that's going to start the mongod service. Since I only use if for local development in my computer, I set myself as the owner:

shell
sudo chown `id -u` /data/db

Now, just running mongod should do the job.

Thanks for reading!

Did this blog post change your life? Or maybe I made a mistake that ruined your day? You can always send me an email to tell me about it.

hello@fantinel.dev

Written by

Matt Fantinel

I’m a web developer trying to figure out this weird thing called the internet. I write about development, the web, games, music, and whatever else I feel like writing about!

About