Mac Run MongoDB error: exception in initAndListen: NonExistentPath: Data directory /data/db not found., t…

this is the main error:

Exception in initandlisten: nonexistentpath: data directory /data/DB not found

Catalina, the latest version of the MAC system, has made a surprising change: it does not allow changes to the root directory (which is also discussed in the forum topic)

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

Unfortunately, this is not explicitly stated in Apple’s Catalina release notes, except for the brief mention in Catalina features:

MacOS Catalina runs on a dedicated read-only system volume

Since the directory /data/DB is encoded as mongodb default directory, one solution is to specify a directory where dbpath is not on the root directory. For example:

mongod --dbpath ~/data/db

This will put the mongodb data in your home directory. Just make sure that the path ~/data/DB does exist

alternative method

An alternative method is to use the instructions in installing mongodb Community Edition on MacOS brew :

brew tap mongodb/brew
brew install mongodb-community

By default, this creates some other files:

Configuration file (/ usr/local/etc/mongod. CONF)

Log directory path (/ usr/local/var/log/mongodb)

To run the data directory path (/ usr/local/var/mongodb), mongod you can:

Run the command manually from the command line (you can use an alias for convenience):

mongod --config /usr/local/etc/mongod.conf

Use to run brew services with mongodb as a service. Note that this will run mongodb as a stand-alone node (rather than a replica set), so functionality depending on oplog (such as changestream) will not work unless you modify the mongod configuration file:

brew services start mongodb-community

https://stackoverflow.com/questions/58283257/mongodb-cant-find-data-directory-after-upgrading-to-mac-os-10-15-catalina

Similar Posts: