Installing MongoDB Community Edition on Ubuntu 20.04.3 LTS on the Raspberry Pi.

Installing MongoDB Community Edition on Ubuntu 20.04.3 LTS on the Raspberry Pi.

In this article I'm installing MongoDB Community Edition on Ubuntu 20.04 on the Raspberry Pi 4 8GB.

The steps (official docs) can be found here.

I tried to install MongoDB CE 5.0, but it didn't work, I got the following message.
[email protected]:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: failed (Result: core-dump) since Tue 2021-08-31 10:16:49 UTC; 664ms ago
       Docs: https://docs.mongodb.org/manual
    Process: 4339 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ILL)
   Main PID: 4339 (code=dumped, signal=ILL)

Aug 31 10:16:48 ubuntu systemd[1]: Started MongoDB Database Server.
Aug 31 10:16:49 ubuntu systemd[1]: mongod.service: Main process exited, code=dumped, status=4/ILL
Aug 31 10:16:49 ubuntu systemd[1]: mongod.service: Failed with result 'core-dump'.

and the reason is described here:

ARM arm64
MongoDB 5.0 requires ARMv8.2-A or later.

Therefore, I'm installing MongoDB 4.4.8. So let's follow these steps:

Import the public key

[email protected]:~$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
OK

Create a list file for MongoDB

[email protected]:~$ 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
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse

Reload local package

[email protected]:~$ sudo apt-get update
Hit:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease
Ign:2 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 InRelease
Get:3 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 Release [4406 B]
Hit:4 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
Hit:5 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
Get:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 Release.gpg [801 B]
Hit:7 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
Get:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 Packages [6291 B]
Get:9 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse amd64 Packages [6548 B]
Fetched 18.0 kB in 2s (7484 B/s)
Reading package lists... Done

Install MongoDB Community Edition

[email protected]:~$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  mongodb-database-tools mongodb-mongosh mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed:
  mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 134 MB of archives.
After this operation, 421 MB of additional disk space will be used.
Get:1 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-database-tools arm64 100.5.0 [44.5 MB]
Get:2 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-mongosh arm64 1.0.5 [37.2 MB]
Get:3 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-shell arm64 5.0.2 [13.0 MB]
Get:4 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-server arm64 5.0.2 [22.9 MB]
Get:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-mongos arm64 5.0.2 [16.3 MB]
Get:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-database-tools-extra arm64 5.0.2 [7752 B]
Get:7 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-database arm64 5.0.2 [3536 B]
Get:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org-tools arm64 5.0.2 [2892 B]
Get:9 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0/multiverse arm64 mongodb-org arm64 5.0.2 [2928 B]
Fetched 134 MB in 2min 50s (787 kB/s)
Selecting previously unselected package mongodb-database-tools.
(Reading database ... 66995 files and directories currently installed.)
Preparing to unpack .../0-mongodb-database-tools_100.5.0_arm64.deb ...
Unpacking mongodb-database-tools (100.5.0) ...
Selecting previously unselected package mongodb-mongosh.
Preparing to unpack .../1-mongodb-mongosh_1.0.5_arm64.deb ...
Unpacking mongodb-mongosh (1.0.5) ...
Selecting previously unselected package mongodb-org-shell.
Preparing to unpack .../2-mongodb-org-shell_5.0.2_arm64.deb ...
Unpacking mongodb-org-shell (5.0.2) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../3-mongodb-org-server_5.0.2_arm64.deb ...
Unpacking mongodb-org-server (5.0.2) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../4-mongodb-org-mongos_5.0.2_arm64.deb ...
Unpacking mongodb-org-mongos (5.0.2) ...
Selecting previously unselected package mongodb-org-database-tools-extra.
Preparing to unpack .../5-mongodb-org-database-tools-extra_5.0.2_arm64.deb ...
Unpacking mongodb-org-database-tools-extra (5.0.2) ...
Selecting previously unselected package mongodb-org-database.
Preparing to unpack .../6-mongodb-org-database_5.0.2_arm64.deb ...
Unpacking mongodb-org-database (5.0.2) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../7-mongodb-org-tools_5.0.2_arm64.deb ...
Unpacking mongodb-org-tools (5.0.2) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../8-mongodb-org_5.0.2_arm64.deb ...
Unpacking mongodb-org (5.0.2) ...
Setting up mongodb-mongosh (1.0.5) ...
Setting up mongodb-org-server (5.0.2) ...
Adding system user `mongodb' (UID 112) ...
Adding new user `mongodb' (UID 112) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 119) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
Setting up mongodb-org-shell (5.0.2) ...
Setting up mongodb-database-tools (100.5.0) ...
Setting up mongodb-org-mongos (5.0.2) ...
Setting up mongodb-org-database-tools-extra (5.0.2) ...
Setting up mongodb-org-database (5.0.2) ...
Setting up mongodb-org-tools (5.0.2) ...
Setting up mongodb-org (5.0.2) ...
Processing triggers for man-db (2.9.1-1) ...

Reload the daemon

sudo systemctl daemon-reload

Start MongoDB after a reboot

sudo systemctl enable mongod

Start MongoDB process.

sudo systemctl start mongod

Check the status of the MongoDB service.

[email protected]:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-08-31 10:38:35 UTC; 4s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 7899 (mongod)
     CGroup: /system.slice/mongod.service
             └─7899 /usr/bin/mongod --config /etc/mongod.conf

Aug 31 10:38:35 ubuntu systemd[1]: Started MongoDB Database Server.

Connecting to MongoDB

[email protected]:~$ mongo
MongoDB shell version v4.4.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a41a4c7d-fecb-47d6-9a1d-5dc206605a56") }
MongoDB server version: 4.4.8
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting:
        2021-08-31T10:38:35.576+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2021-08-31T10:38:35.788+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>

and don't forget to secure MongoDB!