Instructions on 2 ways to install MongoDB on Raspberry Pi

In this tutorial, TipsMake will guide you through the process of installing and setting up the MongoDB server software on your Raspberry Pi.

This article will show you 2 different ways to install MongoDB on Pi.

The first way is to install MongoDB on Raspbian. The Raspbian repository offers an older version of MongoDB (2.4.14) as newer ARM builds of MongoDB require ARM64 and Raspbian is only 32 bits.

The second way is to install the server software onto a 64-bit version of Ubuntu. Using a 64-bit version of Ubuntu will give you access to a newer version of the MongoDB software.

Instructions on 2 ways to install MongoDB on Raspberry Pi Picture 1Instructions on 2 ways to install MongoDB on Raspberry Pi Picture 1

Install MongoDB on Raspbian

In this first part, we will show you the steps to install MongoDB on a Raspberry Pi running Raspbian.

If you rely on features only available in the newer versions of MongoDB, then you need to install Ubuntu and follow the steps in the section titled 'Installing MongoDB on Ubuntu' below.

Step 1. The first step is to update and upgrade all existing packages by running the command below:

sudo apt update sudo apt upgrade

Step 2. Now, install the MongoDB server from the Raspbian repository.

Run the following command to install the software.

sudo apt install mongodb

Step 3. With the server software installed, go ahead and start it up.

The following two commands will enable and start the MongoDB service.

sudo systemctl enable mongodb sudo systemctl start mongodb

Step 4. Once MongoDB is installed, you can run the following command to interact with the database using the command line.

mongo

Install MongoDB on Ubuntu

For this section, you need to be running a 64-bit version of Ubuntu Server.

Using Ubuntu, you can install newer versions of MongoDB. For this part of the tutorial, the article will show you how to install MongoDB 4.2 into your Raspberry Pi.

Step 1. Before starting, make sure Ubuntu is up to date by running the following two commands.

sudo apt update sudo apt upgrade

Step 2. With everything updated, the next step is to add the GPG MongoDB key to their 4.2 repository.

To add this key to the local key sequence, you can run the following command.

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

Step 3. You have added the GPG key. Now, we need to add MongoDB 4.2 repository.

To add a MongoDB repository, you need to run the command below.

echo "deb [arch = 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

Step 4. Since the package list has been modified, you need to update the package list again by running the following command.

sudo apt update

Step 5. Finally, let's install MongoDB onto the Raspberry Pi using the package manager.

The command below will install the MongoDB server software and it's the command line tools.

sudo apt install mongodb-org

Step 6. Now, you can move on to enabling the MongoDB service so it loads on boot.

Do this using the following two commands.

sudo systemctl enable mongod sudo systemctl start mongod

The second command will start the MongoDB server, so you can interact with it immediately.

Step 7. If you want to interact with the MongoDB installation on your Raspberry Pi, you can use the following command.

mongo

This command starts the Mongo command line tool.

Check database and Mongo service

Now, you should check if you have successfully set up MongoDB on your Raspberry Pi or not.

Step 1. The first thing to do is check the status of the MongoDB server. Run the following command to retrieve the state of the "mongod" service.

sudo systemctl status mongod

If everything is running as it should, you should see a response as shown below.

● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-02-06 10:38:54 UTC; 14min ago https://docs.modb.org/manual Main PID 1626 (mongod) CGroup /system.slice/mongod.service └─1626 / usr / bin / mongod --config /etc/mongod.conf Feb 06 10:38:54 ubuntu systemd [1]: Started MongoDB Database Server.

The service must be marked as 'enabled' and 'Active:' should be set to 'active (running)'.

Step 2. Next, you can check the status of Mongo itself by retrieving its connection status.

mongo --eval 'db.runCommand ({connectionStatus: 1})'

Using the following example command, you can use the mongo command-line tool to check the status of the connections.

MongoDB server version: 4.2.3 {"authInfo": {"authenticatedUsers": [], "authenticatedUserRoles": []}, "ok": 1}

As you can see from the result, the version of the MongoDB server in the example is 4.2.3 and the example command returns 'ok' as 1.

4 ★ | 23 Vote