[Updated: 28 Feb 2019] Time to lose this post! The MongoDB 3.4 binaries have vanished from the Debian buster ARM repository BUT I now have MongoDB 4.0.6 running under Ubuntu 18.04 on a Raspberry Pi 3B+ Check out this new post!
I’ve been asked multiple times if MongoDB 3.2 (or greater) can run on a Raspberry Pi. The answer has always been “no” — as you need a 64-bit OS to run versions >= 3.2. Some 64-bit Linux OS’s are starting to become available for R-Pi that, in theory, could run 64-bit MongoDB. I finally found a configuration that was easy to install and use. I now have MongoDB 3.4.18 running under Debian buster on a Raspberry Pi 3 — with a few caveats 😉
The Debian buster release for Raspberry Pi 3 is NOT yet an official image. The hardware still needs the non-free R-Pi firmware to boot. NOTE: the latest image WILL work for the new R-Pi 3B+. There are a growing number of apps that run under buster 🙂 My install is strictly terminal based — or headless (via ssh). The MongoDB utilities are also (now) ported. You can run “mongod,” “mongos,” the “mongo” shell and utilities such as “mongoimport,” “mongodump,” and “mongorestore” from the local command line or via ssh.
Here is the how-to:
- get and install the Debian buster image on a microSD Card
- boot the R-Pi 3 under Debian buster
- update the OS via “update” and “upgrade”
- install MongoDB via “apt-get install”
- configure memory and swap
- test out your configuration
- put data into MongoDB database(s)
You can get info-on and pointers-to the latest Debian buster image for Raspberry Pi 3 on the Debian Wiki. There is a section that shows where and how to download the current image. Make sure you use the latest files. As of 30 January 2018, you can obtain the image via “wget” or on a Mac, “curl -O”:
$ wget https://people.debian.org/~gwolf/raspberrypi3/20181204/20181204-raspberry-pi-3-buster-PREVIEW.img.xz
You should unzip and burn this image to a microSD card for your R-Pi 3. The larger and faster, the better. I used a SanDisk Ultra 32GB microSDHC UHS-I Card with good success. You burn the image to the card as “normal” – i.e. like you would for Raspbian or Noobs.
Place the microSD card in your R-Pi 3 and boot. I assume that your R-Pi is connected to the network via ethernet with DHCP configured. I believe that Debian buster on R-Pi still does not support WiFi but that is outside the scope of this simple how-to.
The login (as mentiond on the Debian Wiki) is “root” with password, “raspberry.” After login, do the customary update/upgrade as “root”:
apt-get install mongodb
There are a few steps to complete before running MongoDB. MongoDB will run without these but you will probably encounter issues. You will need to do these after every reboot, unless you create a script 😉 So, configure kernel memory allocation per MongoDB recommendations:
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
MongoDB needs a fair amount of memory to work with — especially if you want to import or export (or “dump” or “restore”). Until I created a swap space, I encountered a few hangs and/or significant slow-downs. The R-Pi 3 only has 1GB of RAM so I suggest making a 2GB swap space:
chmod 600 /tmp/theswap
dd if=/dev/zero of=/tmp/theswap bs=1M count=2048
You can now start-up MongoDB:
service mongodb start
and check status:
service mongodb status
you can stop with:
service mongodb stop
If you want to run MongoDB utilities from another computer with the “target” being a DB on the R-Pi 3. Make sure you enable remote connections on the R-Pi. Edit the /etc/mongodb.conf file and change the “bind-ip” to:
bind_ip = 0.0.0.0
This will enable connections from any IP address. For example, my R-Pi has the IP address of 10.0.0.187. I could restore a DB “dump” directory from my Macintosh running MongoDB 3.6 via:
mongorestore --host 10.0.0.187
You can import a JSON DB from your local host to the R-Pi via:
mongoimport --host 10.0.0.187 --db bldata --collection images --file bl_images.json
The “mongo” shell works well and I have not experienced any issues:
MongoDB shell version v3.4.18
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.18
Welcome to the MongoDB shell.
> show databases;
> use bldata;
switched to db bldata
> show collections;
"db" : "bldata",
"collections" : 1,
"objects" : 1637919,
"avgObjSize" : 977.5499405037734,
"dataSize" : 1601147621,
"storageSize" : 584765440,
"numExtents" : 0,
"indexes" : 1,
"indexSize" : 16314368,
"ok" : 1
Note: Your mileage may vary! I do NOT recommend using this configuration in a production environment. Debian buster for Raspberry Pi 3 is NOT officially released.
So, here you go. A 64-bit MongoDB running on an R-Pi 3. Please LMK if you have questions or issues by leaving a comment.