Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

macos

mongodb

I updated to MacOS 10.15 (Catalina) today. When I run mongod in the terminal it cannot find the /data/db directory:

➜  /Users/william > mongod 2019-10-08T17:02:44.183+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none' 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] MongoDB starting : pid=43162 port=27017 dbpath=/data/db 64-bit host=Williams-MacBook-Pro-6.local 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] db version v4.0.3 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] allocator: system 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] modules: none 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] build environment: 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten]     distarch: x86_64 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten]     target_arch: x86_64 2019-10-08T17:02:44.209+0800 I CONTROL  [initandlisten] options: {} 2019-10-08T17:02:44.211+0800 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating 2019-10-08T17:02:44.211+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets... 2019-10-08T17:02:44.211+0800 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock 2019-10-08T17:02:44.211+0800 I CONTROL  [initandlisten] now exiting 2019-10-08T17:02:44.211+0800 I CONTROL  [initandlisten] shutting down with code:100 ➜  /Users/william >  

I tried to install MongoDB with brew:

brew install mongodb  ➜  /Users/william > brew install mongodb Updating Homebrew... Error: mongodb: unknown version :mountain_lion 

Any help?

like image 642
William Hu Avatar asked Oct 08 '19 09:10

William Hu


People also ask

Where is MongoDB folder on Mac?

The databases are stored in the /usr/local/var/mongodb/ directory. The mongod. conf file is here: /usr/local/etc/mongod.

Where is my MongoDB directory?

The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the following command sequence. Then you need to specify set the dbpath to the created directory in mongod.exe.

What directory is MongoDB?

By default, MongoDB listens for connections from clients on port 27017 , and stores data in the /data/db directory. On Windows, this path is on the drive from which you start MongoDB. For example, if you do not specify a --dbpath , starting a MongoDB server on the C:\ drive stores all data files in C:\data\db .


1 Answers

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 
like image 76
kevinadi Avatar answered Oct 20 '22 19:10

kevinadi