MacOS Catalina and MongoDB
mongodb macOS databaseI recently upgraded my macOS to Catalina but realized it broke my local MongoDB server setup. During server start it started throwing error-
020-07-14T18:53:04.910-0700 I CONTROL [initandlisten] MongoDB starting : pid=13312 port=27017 dbpath=/data/db 64-bit host=Purans-MacBook-Pro.local
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] db version v3.4.10
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2r 26 Feb 2019
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] allocator: system
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] modules: none
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] build environment:
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] distarch: x86_64
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] target_arch: x86_64
2020-07-14T18:53:04.911-0700 I CONTROL [initandlisten] options: {}
2020-07-14T18:53:04.913-0700 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2020-07-14T18:53:04.913-0700 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-07-14T18:53:04.913-0700 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2020-07-14T18:53:04.913-0700 I CONTROL [initandlisten] now exiting
2020-07-14T18:53:04.913-0700 I CONTROL [initandlisten] shutting down with code:100
After some head scratching, it turns out Catalina now removes all access to the root folder /. MongoDB by default uses /data/db to store all its data. Now with Catalina, since / is no longer accessible MongoDB failed to start. It did trigger a bit of a panic to not see my data in /data directory. But, after doing some more digging I found MacOS actually moved the data from the root folder to the shared users folder-
/Users/Shared/Relocated\Items
So, I had to move the db/data from the shared relocated folder to my home folder-
mv /Users/Shared/Relocated\Items/Security/data/db /Users/<username>
and then start the MongoDB server with that path-
mongod --dbpath ./data/db
This time it started without issues!