MongoDB can't find data directory after upgrading to Mac OS 10.15 (Catalina)

This is the main error:

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

Catalina has a surprise change: it won't allow changes to the root directory (this was discussed in a forum thread as well):

% sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system

Unfortunately, this is not spelled out explicitly in Apple's Catalina release notes, other than a brief mention in Catalina features:

macOS Catalina runs in a dedicated, read-only system volume

Since the directory /data/db is coded as MongoDB default, a workaround is to specify a different dbpath that is not located on the root directory. For example:

mongod --dbpath ~/data/db

This will place MongoDB's data in your home directory. Just make sure that the path ~/data/db actually exists.

Alternative method

An alternative method is to follow the instructions at Install MongoDB Community Edition on macOS by leveraging brew:

brew tap mongodb/brew
brew install mongodb-community

This will create some additional files by default:

  • the configuration file (/usr/local/etc/mongod.conf)
  • the log directory path (/usr/local/var/log/mongodb)
  • the data directory path (/usr/local/var/mongodb)

To run mongod you can either:

  • Run the command manually from the command line (this can be aliased for convenience):

    mongod --config /usr/local/etc/mongod.conf
    
  • Run MongoDB as a service using brew services. Note that this will run MongoDB as a standalone node (not a replica set), so features that depends on the oplog e.g. changestreams will not work unless you modify the mongod configuration file:

    brew services start mongodb-community
    

After installing Catalina, you might have a folder on your Desktop called Relocated Items. You can find the data/db folder inside the Security folder.

All I had to do was move the Security/data/db, specifically data/db and place it inside my home folder.

You can do this with the Finder app or with the terminal by running the following command:

sudo mv /Users/Shared/Relocated\ Items/Security/data ~/

After that run: mongod --dbpath ~/data/db

It's up to you to create the alias


Kevinadi already did justice to the question, however this is how I went about solving the problem:

After installing mongodb-community

  1. sudo mkdir -p /System/Volumes/Data/data/db (Create the data/db folder)
  2. sudo chown -Rid -un/System/Volumes/Data/data/db (Give permissions)
  3. mongod --dbpath=/System/Volumes/Data/data/db (Change dbpath of mongodb)
  4. mongod (Runs well)

I found this article on installing mongodb very useful

Tags:

Macos

Mongodb