This article notes the steps to install Mongodb on a Raspberry pi4.
Prepare OS
Please Install the OS on the SD CARD, the Operating System should be UBUNTU SERVER 20.04.5 LTS (64-BIT).
Configure WIFI Connection
After writing the OS to the SD CARD, an HD called System-boot appeared.
Open network-config in Notepad.
Enter the SSID and Password of the Access-point in wifis, also add “” between the SSID and Password.
Installation
Install Mongodb on Raspberry PI4.
SHH
Access Raspberry PI using SSH Client.
ssh ubuntu@<raspberry-pi-ip-address>.
Default Passwordはubuntuです。
Step 1: Update Raspberry Pi Packages
To begin installing MongoDB on your Raspberry Pi device, make sure the packages on your system are up-to-date and update the packages using the following command
sudo apt update sudo apt upgrade |
Step 2: Install MongoDB
Step2.1
Install MongoDB 4.4 GPG key.
wget -qO – https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add – |
Step2.2
Add the source location of the MongoDB package.
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 |
Step2.3
Download the MongoDB package details.
sudo apt-get update |
Step2.4
Install MongoDB.
sudo apt-get install -y mongodb-org |
Run MongoDB
Ubuntu 20.04 uses Systemd to run background services, so set mongod to run in the background.
# Ensure mongod config is picked up: sudo systemctl daemon-reload # Tell systemd to run mongod on reboot: sudo systemctl enable mongod # Start up mongod! sudo systemctl start mongod |
Check Result
You can verify that the service is running correctly by executing the following command.
$ sudo systemctl status mongod |
Activeはfailedです。なにか間違ってるのでもう一度インストールしていきましょう。
Install Again
This error indicates that the CPU is incompatible with mongodb.
Step1
Execute the following command to stop the mongod process
sudo service mongod stop |
Step2
Remove all previously installed MongoDB packages.
sudo apt-get purge mongodb-org* |
Step3
Delete the MongoDB database and log files.
sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb |
Step4
Import the public key used by the package management system.
wget -qO – https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add – 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 |
Step5
Update Apt.
sudo apt-get update |
Step6
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 |
Step7
Check the Installation with the mongod command.
ubuntu@ubuntu:~$ mongod –version db version v4.4.8 Build Info: { “version”: “4.4.8”, “gitVersion”: “83b8bb8b6b325d8d8d3dfd2ad9f744bdad7d6ca0”, “openSSLVersion”: “OpenSSL 1.1.1f 31 Mar 2020”, “modules”: [], “allocator”: “tcmalloc”, “environment”: { “distmod”: “ubuntu2004”, “distarch”: “aarch64”, “target_arch”: “aarch64” } } |
Result
Done!
Network Configuration
Next, if you want to make the database available to other computers on the network,
Bind MongoDb to the Raspberry Pi’s public IP address and open port 27017 on the Raspberry Pi’s firewall.
MongoDb IP address
Modify mongod.conf in nano Editor.
sudo nano /etc/mongod.conf |
Change bindIp to “0.0.0.0”.
net: port: 27017 bindIp: 0.0.0.0 |
Restart mongod
sudo systemctl restart mongod |
Open Pi4 Port 27017
sudo ufw allow 27017/tcp |
Test
I will use VS Code with MongoDB for VS Code plugin in my local pc to test the connection of MongoDB, installed in raspberry-pi4.
Add a new Connection with Add Connection.
Click Connect.
Access MongoDB on your Raspberry with the following Format.
mongodb://Your Raspberry Ip Address:27017
If the word “Connected” is displayed, it is OK.