MongoDB on MacOS Catalina 10.15: “exception in initAndListen: 29 Data directory /data/db not found”

By default, MongoDB usually stores it’s data files when running on MacOS under /data/db. After upgrading to Catalina 10.15, when starting MongoDB I get this error:

STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating

According to this question and answer here, Catalina no longer allows apps to read or write to non-standard folders beneath / so you need to move the data files elsewhere. After my upgrade, the files were moved to a ‘Relocated Items/Security’ folder. Moving them into my user dir and then starting up with the suggested:

mongod --dbpath ~/data/db

fixes the issue.