MongoDB 5.0.5 for Raspbian Pi OS (64-bit)

[UPDATED: 12 Jan 2022 with MongoDB 5.0.5 binaries] There is no official support from MongoDB for Debian ARM 64 or Raspbian64 Linux OS (now known as Raspberry Pi OS 64-bit).  You can, however, compile the MongoDB Community Edition from source.  I did just that 🙂  It did, however, take three days and a burnt Raspberry Pi 4 to accomplish 🙁  I’ll provide a link to instructions to create the executables for mongod, mongos and mongo — as well as provide a few tips to successfully compile.  Better and easier than that, I provide links to already compiled versions with instructions on how to install and use.

I recently decided to “check-in” on the status of Raspbian64, the 64 bit version of Raspberry Pi OS which is not yet released. I had been using Ubuntu Server 20.04 ARM 64-bit on a couple of Raspberry Pi 4s for various projects. One benefit of Ubuntu was official support for MongoDB. I was looking for a complete optimized Raspbian OS with GUI AND MongoDB. Searching around, I did not find what I wanted. I decided to try and create it.

You’ll need to find and install the latest Raspbian64 image. Use the “full” version as opposed to “lite” as you need all the tools, such as dev libraries, g++-8 and git that come with the full version. Not that you could not use “lite” and install everything needed 😉 This is the version I use with its GUI as it has great internet and development tools. I can also use via VNC in headless mode.

If you really want to compile MongoDB Community Edition 4.4.8 from source, you can find instructions in this thread in the MongoDB Community Forums. NOTE that you will need to add at least a 4GB swap file on your 4GB RAM R-Pi 4. You should change the git command that grabs version 4.2.8 so that you get the latest: 4.4.8 or 5.0.5.

git clone -b r4.4.8 https://github.com/mongodb/mongo.git

OR, for version 5.0.5

git clone -b r5.0.5 https://github.com/mongodb/mongo.git

Compiling is straightforward but I had a few issues along the way. I used a Raspberry Pi 4 in a Flirc case with a USB 3 attached SSD. I have had my Pi 4 overclocked to 2GHz with no issues or overheating for quite some time. I love the Flirc case as it looks good and the whole aluminum case is a big heatsink. The first couple of times I tried to compile MongoDB from source, the build would just die after an hour or so. By monitoring the Pi with another ssh login, it looked like it was running out of real and swap memory. I could also see the 4 cores were running at over 90% usage. I upped the swap file to 2GB and tried again. This time, the build lasted over 4 hours before hanging (died silently). I picked up the Pi 4 case and almost burned my hand (ouch!). Being foolish, I tried again — with, of course the same result — a hung Pi that now had the electronic overheat smell 🙁 I moved the SSD to my *stock* Raspberry Pi 400 and tried again. Fortunately, the compile (more-or-less) picked up where it died. After about 5 hours, the compile completed without errors. I now had executable binaries for mongod, mongos and mongo (the “old” Javascript shell).

I am providing the 4.4.8 binaries and 5.0.5 binaries to save folks time and effort.

MongoDB 4.4.8:
sha256: 1b50ab43f5ee39b74603563ce7c88ff2654338dca7ed58df24569900aaf44f08  raspbian_mongodb_4.4.8.gz

MongoDB 5.0.5:
sha256: 9eaf5797bf2a54ba73adb4652668dfe5bf0d54efc387053b6241a5e3c38c7cc9  raspbian_mongodb_5.0.5.gz

The usual disclaimers apply: use at your own risk, no warranties of any kind, your mileage may vary, etc.  Please do NOT directly link to the file.  You can link to this blog or specific blog entry.

Install and use

Ensure you are running the latest version of Raspbian64 OS with all updates. Download and unzip the raspbian_mongodb_4.4.8.gz or raspbian_mongodb_5.0.5.gz file.  You’ll have 3 files, mongod, mongos and mongo. Move the executables to /usr/bin and change owner and group to root.  Ensure permissions are set to executable.

For version 4.4.8:

tar zxvf raspbian_mongodb_4.4.8.gz
sudo mv mongo* /usr/bin
sudo chown root:root /usr/bin/mongo*
sudo chmod 755 /usr/bin/mongo*

Create the mongodb user.

sudo adduser --no-create-home --disabled-login mongodb

Create the configuration file:  /etc/mongodb.conf and add the following lines:

sudo vi /etc/mongodb.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/db
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

Create the log file and data directory. Change owner and group.

sudo mkdir -p /var/log/mongodb/
sudo chown -R mongodb:mongodb /var/log/mongodb/
sudo mkdir /data
sudo chmod 777 /data
sudo mkdir -p /data/db
sudo chown -R mongodb:mongodb /data/db

Create the systemctl service file to stop/start mongod process and add the following lines:

sudo vi /lib/systemd/system/mongodb.service
[Unit]
Description=An object/document-oriented database
Documentation=man:mongod(1)
After=network.target

[Service]
User=mongodb
Group=mongodb
# Other directives omitted
# (file size)
LimitFSIZE=infinity
# (cpu time)
LimitCPU=infinity
# (virtual memory size)
LimitAS=infinity
# (locked-in-memory size)
LimitMEMLOCK=infinity
# (open files)
LimitNOFILE=64000
# (processes/threads)
LimitNPROC=64000
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf

[Install]
WantedBy=multi-user.target

You can now start/stop the mongodb service (mongod). Remember to stop gracefully before rebooting your system!

$ sudo service mongodb start

$ sudo service mongodb status

● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-08-07 11:27:26 PDT; 1 day 1h ago
     Docs: man:mongod(1)
 Main PID: 1771 (mongod)
    Tasks: 33 (limit: 4164)
   CGroup: /system.slice/mongodb.service
           └─1771 /usr/bin/mongod --quiet --config /etc/mongodb.conf

You can also now run mongo, an interactive JavaScript shell interface to MongoDB

$ mongo

MongoDB shell version v4.4.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("328da768-3ae6-4638-9df3-5fb4d32156ff") }
MongoDB server version: 4.4.8

> show databases;
admin   0.000GB
config  0.000GB
local   0.000GB

Let me know in the comments if you have issues or questions.