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!

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

Newsletter? I have it!

I have a newsletter as another way to share what I write on this blog. The main goal is to be able to reach people who don't use RSS or just prefer getting their articles delivered straight into their inbox.

  • No fixed frequency, but at least once at month;
  • I do not plan on having content exclusive to the newsletter. Everything on it will also be on the blog;
  • I will never, ever ever ever, send you any form of spam.

You might also like

View blog

.NET Core - Project version mismatch

1 min read

Solving this cryptic error might take you many hours. Hopefully this will help you out.

Back-End
Read

.NET Core - Method not allowed on PUT and DELETE requests

2 min read

See how to solve this annoying error after deploying your .NET Core API.

Back-End
Read

Setting up Storybook on an Astro project

7 min read

I really, really thought this was gonna be easy.

Front-End
Read

Separating my website's content from its code

4 min read

Having an open source website is great, but having the content stored in the same spot as the code has some issues. On this post I walk through what I did to keep them separated.

Meta
Read