MongoDB 4.2.x (64-bit) on Raspberry Pi 4

Ubuntu 18.04.x (ARM 64-bit) is now available for the Raspberry Pi 4. While not an officially supported OS from either the Foundation or Ubuntu, James A. Chambers has been working on a port for the Raspberry Pi 4. A 64-bit OS is required to run 64-bit MongoDB 4.2.x. MongoDB (the company) just recently provided a 64-bit ARM version for Ubuntu 18.04. I will show how to install this version of MongoDB under Ubuntu 18.04 on the Raspberry Pi 4.

Note that my Raspberry Pi 4 has 4GB RAM. I believe from past experience that 2GB is sufficient to run MongoDB. I have had issues with a 1GB RAM system but worked around by creating a swap disk.

Please read my instructions carefully and copy and paste where you can. I have noticed a couple of typos on the MongoDB website where the “ARM” keyword was missing in some commands.

First, follow the instructions on James A Chambers website to install Ubuntu 18.04. I used “Release v17” but there may now be a newer release. Make sure you have updated the bootloader per James’ Raspberry Pi 4 Bootloader Guide. In short do a “rpi-update” and a “rpi-eeprom-update” under Raspbian BEFORE burning and booting-from the Ubuntu 18.04 image. I booted with ethernet connected to establish keys, etc. with Ubuntu. I chose not to use a GUI but again, James mentions several available in his write-up.

Assuming you have now booted Ubuntu on your R-Pi 4, you will be required to update the “ubuntu” password. You should also do the usual “sudo apt-get update” and “sudo apt-get upgrade.”

Download available at MongoDB but I used “apt-get” to enable updates

To install MongoDB 4.2.x, you can generally follow the Install Guide at MongoDB. The instructions were not quite correct for installing under Ubuntu 18.04 ARM 64. Here is what I used to get things working:

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

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

sudo apt-get update

sudo apt-get install mongodb-org

You can check that “mongod” and “mongo” were installed by displaying version:

ubuntu@ubuntu:~$ mongod --version
db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: aarch64
    target_arch: aarch64

ubuntu@ubuntu:~$ mongo --version
MongoDB shell version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: aarch64
    target_arch: aarch64

You can “start” and “stop” “mongod” via the “service” command. Ensure you stop “mongod” before shutdown of system!

ubuntu@ubuntu:~$ sudo service mongod status
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: https://docs.mongodb.org/manual

ubuntu@ubuntu:~$ sudo service mongod start

ubuntu@ubuntu:~$ sudo service mongod status
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-11-03 22:48:22 UTC; 23s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2114 (mongod)
   CGroup: /system.slice/mongod.service
           └─2114 /usr/bin/mongod --config /etc/mongod.conf

Nov 03 22:48:22 ubuntu systemd[1]: Started MongoDB Database Server.

I have a DB that I use to check the mongodb and tools installs. It is about a 1GB dump with indexes:

ubuntu@ubuntu:~$ mongorestore dump/
2019-11-03T21:54:25.087+0000	preparing collections to restore from
2019-11-03T21:54:25.090+0000	reading metadata for bldata.images from dump/bldata/images.metadata.json
2019-11-03T21:54:25.136+0000	restoring bldata.images from dump/bldata/images.bson
2019-11-03T21:54:28.085+0000	[........................]  bldata.images  47.9MB/1.49GB  (3.1%)
2019-11-03T21:54:31.085+0000	[#.......................]  bldata.images  96.0MB/1.49GB  (6.3%)
...
2019-11-03T21:56:01.085+0000	[#######################.]  bldata.images  1.46GB/1.49GB  (98.1%)
2019-11-03T21:56:03.009+0000	[########################]  bldata.images  1.49GB/1.49GB  (100.0%)
2019-11-03T21:56:03.009+0000	restoring indexes for collection bldata.images from metadata
2019-11-03T21:56:30.666+0000	finished restoring bldata.images (1637919 documents, 0 failures)
2019-11-03T21:56:30.666+0000	1637919 document(s) restored successfully. 0 document(s) failed to restore.

Run “mongo” and do some checking…

ubuntu@ubuntu:~$ mongo
MongoDB shell version v4.2.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("49c4fdbc-04e8-4952-af3b-a9d0e6fd9c2c") }
MongoDB server version: 4.2.1

> show dbs
admin   0.000GB
bldata  0.446GB
config  0.000GB
local   0.000GB
> use bldata
switched to db bldata
> show collections
images
> db.images.findOne()
{
	"_id" : ObjectId("5755aec7a3b2efd38d58a020"),
	"volume" : "0",
	"publisher" : "[G. B. Faelli",
	"title" : "Ro. vrbis excidium. [In verse.]",
	"first_author" : "CURSIUS, Petrus.",
	"pubplace" : "Bologna",
	"book_identifier" : "000840022",
	"date" : 1528,
	"flickr_url" : "http://www.flickr.com/photos/britishlibrary/10996904595",
	"image_idx" : 1,
	"page" : "000011",
	"flickr_id" : "10996904595",
	"flickr_small_source" : "http://farm3.staticflickr.com/2825/10996904595_2382793f75_m.jpg",
	"flickr_small_height" : 227,
	"flickr_small_width" : 240,
	"flickr_medium_source" : "http://farm3.staticflickr.com/2825/10996904595_2382793f75.jpg",
	"flickr_medium_height" : 323,
	"flickr_medium_width" : 342,
	"flickr_original_source" : "http://farm3.staticflickr.com/2825/10996904595_d9c8e1f009_o.jpg",
	"flickr_original_height" : 323,
	"flickr_original_width" : 342,
	"type" : "small"
}
> db.images.find({pubplace: 'Paris'}).count()
135709
> 

I hope this quick guide helps you get MongoDB running on your Raspberry Pi 4. Let me know if you have issues or questions in the comments.

8 thoughts on “MongoDB 4.2.x (64-bit) on Raspberry Pi 4”

  1. Pingback: MongoDB 4.0.11 (64-bit) on Raspberry Pi 3 – AndyFelong.com

  2. I’m trying to run this as a docker and I’m getting the below error:
    E: Unable to locate package mongodb-org

    1. Hi Sethu, This will probably NOT work with Docker – if in 32-bit mode 🙁 I suggest using released 64-bit Ubuntu 18.x Server and follow install instructions on mongodb.com?

      1. Yeh. I figured that I’m using the 32-bit ubuntu os to build my docker image. I think its better to go for 64-bit ubuntu server.
        Thanks for your advice.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top