Like a good Apple nerd, I updated to the latest version of macOS Catalina. If you’re using older 32bit apps Catalina won’t run them. Thankfully, I wasn’t in that position, so I didn’t anticipate any issues. So young so innocent.
As it turns out another chance in Catalina does affect my normal workflow. The change is related to a security improvement that prevents users from creating new files in root.
Not an issue for most things, but MongoDB by default uses /data/db as the location for storing data. To fix this the best solution I came across was to simply change the location from the default to somewhere in your user folder. This is easy to do using the following command in terminal:
Mongo will now work, and you can get on with life.
The course I’m doing uses Cloud 9 (C9) as cloud-based IDE. I’ve basically ignored that side of things and done everything locally on my Mac as that feels more real world to me. Turns out this was a good decision as C9 has recently announced it’s shutting down. Anyway, at times this has made things more difficult though. A good example is when I need to follow instructions to get a particular part of the development environment setup. Because all the instructions are specific to C9 it means I more or less have to figure out how to do it myself on macOS.
This morning I had an example of this exact thing when I needed to install MongoDB. I’m finally at the point that I’m starting to work with a database (hallelujah!) and I needed to get things going on my Mac. Thankfully there’s Google and I quickly found this treehouse article that gave me some clear steps to follow.
Of course it’s never quite that easy. Different machines are set up in different ways, so a guide like this doesn’t always allow for edge cases. So here’s what worked for me:
- Open terminal and use the command
brew update to update Homebrew itself to the latest version
- Now install MongoDB using
brew install mongodb. This will install the latest version
- Next we need to create a folder to house our MongoDB data files. Use the command
sudo mkdir -p /data/db. The instructions I first followed didn’t include sudo and so didn’t work for me. Your milage may vary
- We should now have a place for our data but we need to set the folder permissions using
sudo chown -R `id -un` /data/db
That’s basically it, you should now have a functional install of MongoDB. Open up two terminal windows in the first start the server with the
mongod command. In the second terminal run
mongo to launch the mongo shell for accessing data.