06. Install MongoDB

The first really big difference with how the Raspberry Pi app functions is that now, instead of our database being available on the internet, remember (if you did the Heroku/mLab version first) how we set our Mongo access to 0.0.0.0? Yeah, we're not doing that shit anymore. Now, our database will be running locally on this Raspberry Pi and our server will be running on the Pi and they can just "talk" to each other all damn day without having to go across two different sites back and forth all day. So let's get to it.

Oh! At the time of writing this MongoDB 5.0 has been released, but we are installing version 4.4! While setting this up the first time I used 5.0 and ran in to a handful of issues with getting it up and running and it was a pain in the ass to get it back to a lower version for some reason. So, if you decide that you want the latest version, that's cool, but you're on your own with that. I'm sure it'll work fine once it's all up and running, but personally, I'm good with 4.4. And for what it's worth, 5.0 was released July 13, 2021 and 4.4.9 was released September 21, 2021, if that means anything, who knows, but there's that.

  1. Import the public key

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

2. Do whatever this does

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

3. Update Apt: sudo apt-get update 4. Install MongoDB

sudo apt-get install mongodb-org=4.4.8 mongodb-org-server=4.4.8 mongodb-org-shell=4.4.8 mongodb-org-mongos=4.4.8 mongodb-org-tools=4.4.8

5. Check that everything installed correctly: mongod --version 6. If you see the version number and some other info about Mongo we're good. If something went wrong, I'll refer you to the StackOverflow where I copy/pasted those commands when I totally messed up my gear with 5.0

StackOverflow Link

  1. Typing this command should show that Mongo is enabled, but not running: sudo service mongod status

  2. Restart the Pi: reboot

  3. Once you're back in, sudo service mongod status again. If it says "active (running)" then we're all good!

  4. If you didn't see that it was active, type sudo service mongod start and then mongod

  5. Now do sudo service mongod status and you should see that MongoDB is active and running.

  6. Now let's set it to start up when the Pi boots: sudo systemctl enable mongod.service

  7. Reboot and test it out: reboot

  8. Once you're logged back in: sudo service mongod status and you should see that it's "active"

That really wasn't so bad. It took me wayyyy longer the first time I did this. The hardest part is probably not being able to copy/paste all the commands and double triple checking everything!

Well great! I think we're finally ready to clone our server repo!

Last updated