Installing MongoDB 7.0 on the Raspberry Pi 5 Using XFS
Tags: mongodb, raspberrypi, nosql
Published: 2024-01-20 00:57:42

The Raspberry Pi is awesome, and I've been using it for various fun projects for years. In preparing for this article, I counted six of various vintages doing things around my house, from enabling my garage doors to be opened through Apple Carplay in my car as I approach home, to contributing air traffic control data from aircraft landing and departing nearby Denver International Airport to the [FlightAware project](https://www.flightaware.com/live/).

As a MongoDB fan (and — full disclosure — an employee), I've grown accustomed to the power, flexibility, and ease of use of working with document data model databases in my projects. While the excellent [MongoDB Atlas](https://www.mongodb.com/atlas) cloud offering is always an option (including its big-enough-to-be-useful free tier), for some projects running on devices like Raspberry Pi, it's nice to have a local database. Until recently, though, the most up-to-date version of MongoDB that could be installed on a Raspberry Pi was version 4.4.18. Later versions — including all 5.x, 6.x, and 7.x releases — require the [ARMv8.2-A](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-architecture-armv8-2-a-evolution-and-delivery) microarchitecture when running on ARM64 processors, but the processors used by Raspberry Pi on its models up to and including Raspberry Pi 4 only supported ARMv8.0. This means more recently introduced MongoDB features haven't been available on Pi deployments.

With the recent introduction of the rather splendid Raspberry Pi 5, however, ARMv8.2-A is now supported, and all current MongoDB releases can once again be installed on this amazing device. Pi 5 is blazing fast compared with prior versions, too, and it's plenty capable of allowing you to run all kinds of fun projects and experimentations.

In this article, I'll show you how to install MongoDB Community Edition version 7.0.x on a Pi 5 running Pi OS "bookworm" (the latest versions of MongoDB and Pi OS respectively as of January 2024). Much of this is based on an [earlier article](https://www.mongodb.com/developer/products/mongodb/mongodb-on-raspberry-pi/) written by my colleague Mark Smith, but Mark was constrained by the Pi hardware available at the time he wrote his article to install MongoDB 4.4, so we'll bring that advice up to date. 


## What you will need


- **A Raspberry Pi 5b**: These come in 4GB and 8GB variants. Depending on how ambitious you're planning to be with your projects, I'd recommend an 8GB board, but I've had MongoDB up and running on older Raspberry Pis with as little as 2GB of RAM.

- **A microSD memory card**: This will be the Pi's primary storage. You could probably get a working installation on a  4GB card, but that's not going to leave much room for data or logs. For this article, I'll be using a 128GB U3 card from Samsung. A good quality card from a reputable brand with high read and write speeds is worth the investment.

- **A USB flash drive**: We'll be using this to temporarily boot your Raspberry Pi in order to modify the partitions on your main microSD card before we use it for the first time. You'll need a drive with around 3GB of storage for this and we will be reformatting it so make sure you back up any existing data that's on it first. 

- **A computer to run the Raspberry Pi Imager**: Any machine running Windows or Mac OS will work as long as it can read your microSD card and your USB flash drive. I'll be using my main Mac laptop for this.
 
Now we know what we need, let's review the steps we're going to follow:

**1.** Flash Raspberry Pi OS onto your microSD card and USB flash drive.
**2.** Modify the partitions on your microSD card.
**3.** Create XFS filesystems to run MongoDB on.
**4.** Install and configure MongoDB. 
 
Let's get started.


## Flash Pi OS onto your microSD card and USB flash drive


Raspberry Pi makes a handy tool available for flashing an operating system image onto storage devices. You can download it from [the Raspberry Pi website](https://www.raspberrypi.com/software/). We'll use this tool to flash an operating system image onto both our microSD card and our USB flash drive

The tool gives you a bunch of options as to which operating system to flash, and any of the 64-bit Pi OS or Ubuntu (desktop or server — **not** core) options will work. Just be sure **not** to select a 32-bit version. For this article, I'm going to use Pi OS 64-bit Lite and the instructions assume you do too, but there shouldn't be too many places where you'll need to modify any of the instructions if — for example — you want to run Ubuntu instead. Pi OS Lite does not include a desktop environment, but the image is quite a bit smaller as a result, and I'll be doing everything in a terminal over SSH anyway.

![Screenshot of the Raspberry Pi Imager application showing the Raspberry Pi OS options available for the Raspberry Pi 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3nsc5vyqs14pabews1y.png)

Let's start by flashing your microSD card.

Select your microSD card as the target storage and click **Next**.

![Screenshot of the Raspberry Pi Imager application showing a mounted SD card as the target storage device](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzqsl3gig6lhlksmj8pk.png)

If you've selected one of the Pi OS options to flash, you'll now be asked if you want to apply any OS customizations. I highly recommend you do this. It'll allow you to preconfigure your Pi's hostname, select a username and password (and avoid the pitfall of using a default username and password), apply wireless network settings, set locale details, and enable SSH — including using public key authentication if you wish. If you don't do this now, you'll need to do all those things manually when you first boot your Pi.

![Screenshot of the Raspberry Pi Imager application showing the "Use OS Customizations" dialog box.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7ng6o7sf090rxtlt1tv.png)

Once you've finished configuring the OS customizations you want to apply, start the flashing process. This will take a few minutes to complete. Once it's complete, remove the card from your computer.

> **_IMPORTANT: Do not insert the card into your Pi and boot from it yet._**

Repeat these steps to flash Raspberry Pi OS onto your USB flash drive.


## Modify the partitions on your microSD card


Linux supports several different filesystems, each with its own strengths and weaknesses. It's possible, common even, to have Linux systems with a mix of partitions using different filesystems with each partition being used for a different purpose or application type. 

Without going into detail, the [`XFS`](https://en.wikipedia.org/wiki/XFS) filesystem is particularly well suited to database-type workloads and is MongoDB's recommended filesystem. Pi OS and Ubuntu are both based on Debian Linux and the default filesystem on Debian is `ext4`. In reality, MongoDB will run just fine on `ext4` for any workload you are likely to run on a Raspberry Pi, but you will get a warning message when logging in to the MongoDB shell if it is not running on `XFS`. If, like me, warning messages bug the heck out of you, the following steps will show you how to set up `XFS` on your Pi OS image, starting with modifying the partitions on your microSD card. While setting up `XFS` partitions is not absolutely necessary, it's a useful exercise to go through in case you ever find yourself setting up servers for larger workloads in the future.

When the Raspberry Pi Imager flashed your card, it created two partitions — a ~500MB `FAT32` boot partition and a second ~2GB `ext4` data partition:

![Screenshot of the Mac OS Disk Utility showing the partitions created on a microSD card by the Raspberry Pi Imager application.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffqjgq1r3jih4xurwosc.png)

If you do nothing else, the first time you insert your microSD card into your Pi and boot from it, the `ext4` data partition will be expanded to use up all remaining space on the card. This would be a problem for us as it would leave no space for the `XFS` partitions we want to add.

To prevent this, and before we boot our Pi from the microSD card, we're going to first boot it using the USB flash drive and then carry out the following steps:

**1.** Manually resize the `ext4` data partition on our microSD card to the size we want it to be.
**2.** Using the remaining space on the microSD card, add two additional partitions: one for MongoDB's data files and one for its logs.
 
By taking these steps, when the Pi first boots from the microSD card, the `ext4` file system will be automatically expanded to fill its now larger partition, but the partition itself will not be expanded to take up any additional space on the card.

> **Note:** Over the years, Raspberry Pi has updated and modified the way that the first-boot partition resizing works, and there are a number of articles on the web showing methods to prevent it that are no longer applicable. 

Insert your USB flash drive into your Pi, but **_do not_** insert your microSD card yet. Power on your Pi.

When it first boots, your Pi will power-cycle a couple of times, but after 20 to 30 seconds, it should be available for you to SSH into (assuming you enabled SSH during the flash process). If you didn't enable SSH or for some reason you can't determine the IP address it was allocated, you may need to initially connect it to a keyboard and monitor to log on directly, enable SSH, and get its IP address. Once you are able to SSH onto the Pi, insert your microSD card into the microSD card reader and use the `lsblk` command to inspect its disk and partitions:

```
graeme@pi5Temp:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    1   7.5G  0 disk 
├─sda1        8:1    1   512M  0 part /boot/firmware
└─sda2        8:2    1     7G  0 part /
mmcblk0     179:0    0 119.4G  0 disk 
├─mmcblk0p1 179:1    0   512M  0 part 
└─mmcblk0p2 179:2    0     2G  0 part 

```
The output on my machine shows two devices. The partitions on the `sda` device are already mounted at `/boot/firmware` and `/`, so that's the device the Pi booted from i.e. the USB flash drive. That means the other device — `mmcblk0` — is our microSD card and the device we want to partition. The reported size of the devices confirms this.

Running as a superuser, start the `parted` partitioning utility and select the device to partition:

```
graeme@pi5Temp:~ $ sudo parted
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) select /dev/mmcblk0
Using /dev/mmcblk0

(parted) print                                                            
Model: SD YD4QD (sd/mmc)
Disk /dev/mmcblk0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  541MB   537MB   primary  fat32        lba
 2      541MB   2739MB  2198MB  primary  ext4   
```
My microSD card is 128GB, so I'm going to expand my `ext4` partition to be 30GB, then add a 20GB log partition for MongoDB and use the remaining space for a MongoDB data partition. Let's start by resizing the `ext4` partition. Note that it was listed as partition 2:

```
(parted) resizepart                                                       
Partition number? 2                                                       
End?  [2739MB]? 30.5GB                                                    
(parted) print                                                            
Model: SD YD4QD (sd/mmc)
Disk /dev/mmcblk0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  541MB   537MB   primary  fat32        lba
 2      541MB   30.5GB  30.0GB  primary  ext4
```
Now, we'll add the 20GB MongoDB log partition:

```
(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]? xfs                                            
Start? 30.5GB                                                             
End? 50.5GB                                                               
(parted) print                                                            
Model: SD YD4QD (sd/mmc)
Disk /dev/mmcblk0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  541MB   537MB   primary  fat32        lba
 2      541MB   30.5GB  30.0GB  primary  ext4
 3      30.5GB  50.5GB  20.0GB  primary  xfs          lba
```

Finally, add the MongoDB data partition using the remaining space (~77.5GB):

```
(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]? xfs                                            
Start? 50.5GB                                                             
End? 128GB                                                                
(parted) print                                                            
Model: SD YD4QD (sd/mmc)
Disk /dev/mmcblk0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  541MB   537MB   primary  fat32        lba
 2      541MB   30.5GB  30.0GB  primary  ext4
 3      30.5GB  50.5GB  20.0GB  primary  xfs          lba
 4      50.5GB  128GB   77.7GB  primary  xfs          lba
```

Close `parted` and do a final check to make sure everything looks good using `lsblk`:

```
(parted) quit                                                             
Information: You may need to update /etc/fstab.

graeme@pi5Temp:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    1   7.5G  0 disk 
├─sda1        8:1    1   512M  0 part /boot/firmware
└─sda2        8:2    1     7G  0 part /
mmcblk0     179:0    0 119.4G  0 disk 
├─mmcblk0p1 179:1    0   512M  0 part 
├─mmcblk0p2 179:2    0  27.9G  0 part 
├─mmcblk0p3 179:3    0  18.6G  0 part 
└─mmcblk0p4 179:4    0  72.3G  0 part
```

If everything looks good, you can power down your Pi, remove the USB flash drive (we won't be needing it any more) and with your microSD card still in the Pi's microSD card reader, power up the Pi again.


## Create XFS filesystems to run MongoDB on


Your Pi will now boot using the microSD card. As before when we booted using the USB flash drive, your Pi will power-cycle a couple of times, but after 20 to 30 seconds it should be available for you to SSH into. Note you may have to delete some entries in the ssh known_hosts file on the machine from which you are connecting to the Pi to avoid SSH connection errors due to the remote host having changed identity. On "UNIX-ish" operating systems like Mac and Linux, this is usually in a hidden directory called `.ssh` in your home directory. On Windows, it will depend on terminal application you are using. PuTTY, for example, stores known hosts in the registry at `\HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys`. 

Once you are able to SSH onto the Pi, do so and inspect its disk and partitions:

```
graeme@pi5PIOS:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0     179:0    0 119.4G  0 disk 
├─mmcblk0p1 179:1    0   512M  0 part /boot/firmware
├─mmcblk0p2 179:2    0  27.9G  0 part /
├─mmcblk0p3 179:3    0  18.6G  0 part 
└─mmcblk0p4 179:4    0  72.3G  0 part
 
graeme@pi5PIOS:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           805M  5.1M  800M   1% /run
/dev/mmcblk0p2   28G  1.7G   25G   7% /
tmpfs           4.0G     0  4.0G   0% /dev/shm
tmpfs           5.0M   48K  5.0M   1% /run/lock
/dev/mmcblk0p1  510M   63M  448M  13% /boot/firmware
tmpfs           805M     0  805M   0% /run/user/1000
```
In particular, we're looking to confirm our `ext4` filesystem has been expanded to fill its full 30GB partition, and we have the two empty partitions ready to have `XFS` filesystems added.

As everything looks good, we can add the `XFS` filesystems. Start by making sure Pi OS is fully up-to-date by running `apt-get update` and `apt-get upgrade`.

```
graeme@pi5PIOS:~ $ sudo apt-get -y update
graeme@pi5PIOS:~ $ sudo apt-get upgrade 
```
Now, we can install `XFS` itself:

```
graeme@pi5PIOS:~ $ sudo apt-get -y install xfsprogs
```
If you recall the output from `lsblk`, our two empty partitions  are `mmcblk0p3` and `mmcblk0p4`. To create an `XFS` file system on each, run the following commands:

```
graeme@pi5PIOS:~ $ sudo mkfs.xfs /dev/mmcblk0p3
graeme@pi5PIOS:~ $ sudo mkfs.xfs /dev/mmcblk0p4
```

Now we have our two partitions with `XFS` filesystems, we need to mount them in the right locations within our directory structure. MongoDB writes logs to `/var/log/mongodb` and data files to `/var/lib/mongodb`, so let's go ahead and create those:

```
graeme@pi5PIOS:~ $ sudo mkdir /var/log/mongodb
graeme@pi5PIOS:~ $ sudo mkdir /var/lib/mongodb
```

We can now mount the filesystems. `mmcblk0p3` is our 20GB log partition and `mmcblk0p4` is our larger data partition, so the commands to run are:

```
graeme@pi5PIOS:~ $ sudo mount /dev/mmcblk0p3 /var/log/mongodb
graeme@pi5PIOS:~ $ sudo mount /dev/mmcblk0p4 /var/lib/mongodb
```

Confirm the mounts were successful:

```
graeme@pi5PIOS:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0     179:0    0 119.4G  0 disk 
├─mmcblk0p1 179:1    0   512M  0 part /boot/firmware
├─mmcblk0p2 179:2    0  27.9G  0 part /
├─mmcblk0p3 179:3    0  18.6G  0 part /var/log/mongodb
└─mmcblk0p4 179:4    0  72.3G  0 part /var/lib/mongodb
```

The final step in this stage is to add entries to the `fstab` file so that the new `XFS` filesystems are mounted each time your Pi is booted. To do this, we'll use the `blkid` command to get the `PARTUUID` of the two `XFS` partitions:

```
graeme@pi5PIOS:~ $ sudo blkid /dev/mmcblk0p3
/dev/mmcblk0p3: UUID="7fee4d44-6820-4e90-861f-defd195e5205" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="de9255b2-03"
graeme@pi5PIOS:~ $ echo 'PARTUUID=de9255b2-03 /var/log/mongodb xfs defaults 1 1 ' | sudo tee -a /etc/fstab
 
graeme@pi5PIOS:~ $ sudo blkid /dev/mmcblk0p4
/dev/mmcblk0p4: UUID="d8a6e88b-fba9-4719-96d4-327829c5cd8f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="de9255b2-04"
graeme@pi5PIOS:~ $ echo 'PARTUUID=de9255b2-04 /var/lib/mongodb xfs defaults 1 1 ' | sudo tee -a /etc/fstab
```

Reboot your Pi and do a final check to confirm the `XFS` file systems have been mounted as expected.
 

## Install and configure MongoDB

With our disk partitioned and `XFS` file systems in place, we're now ready to install MongoDB.

> Do **not** simply run `sudo apt-get install mongoDB`. Like much software, the version of MongoDB in the standard repositories for most Linux distributions is _very_ old and most likely no longer supported. The steps in this guide will show you how to install the latest version from MongoDB's own repositories.

At the time of writing, there are pre-built MongoDB packages for both Debian and Ubuntu which, like Pi OS, is Debian-based. However, the Debian packages only support AMD_64 architectures, whereas the Ubuntu packages also support the ARM64 architecture used by the Raspberry Pi. As of January 2024, the latest Pi OS release is based on Debian 12 ("bookworm"), as is Ubuntu 22.04 LTS ("Jammy"), so we'll use the MongoDB packages for that version of Ubuntu. It's worth pointing out that supported platforms and versions will evolve over time, so it's always worth confirming availability in the official [MongoDB installation documentation](https://www.mongodb.com/docs/manual/administration/install-on-linux/).

To get started, we need to install the MongoDB public GPG key:

```
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
```

Next, create an apt source list file for the Ubuntu 22.04 packages:

```
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
```

Reload the local package database:

```
sudo apt-get update
```

And, finally, install MongoDB:

```
sudo apt-get install -y mongodb-org
```

Yay — MongoDB is now installed!!! Before we can run it, though, we need to change ownership of the `/var/log/mongodb` and `/var/lib/mongodb` directories to a user and group created by the installation process.

```
sudo chown mongodb:mongodb /var/log/mongodb/
sudo chown mongodb:mongodb /var/lib/mongodb/
```

Pi OS uses the `systemd` init system, so to start, stop, or check the run status of MongoDB, we use the `systemctl` command:

```
graeme@pi5PIOS:~ $ sudo systemctl start mongod
graeme@pi5PIOS:~ $ sudo systemctl status mongod
graeme@pi5PIOS:~ $ sudo systemctl stop mongod
```

If you want MongoDB to start automatically each time your Pi boots, use the `systemctl` command to "enable" it:

```
graeme@pi5PIOS:~ $ sudo systemctl enable mongod
```

Start MongoDB and use the `systemctl status` command to confirm it is running. If everything is good, you should now be able to connect using the `monogsh` MongoDB shell:

```
graeme@pi5PIOS:~ $ mongosh
Current Mongosh Log ID:	659f7f5de9e80a30c96e4be1
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.1
Using MongoDB:		7.0.5
Using Mongosh:		2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2024-01-10T22:38:09.322-07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2024-01-10T22:38:09.322-07:00: vm.max_map_count is too low
------

test>
```

So far so good, but we want to fix those two warnings that were generated. The first, about access control, is the important one, and we'll handle that in a moment, but first, let's get rid of the `max_map_count` warning. As with running on `XFS`, this is also probably unnecessary for any workload we're likely to deploy on a Raspberry Pi, but the MongoDB [Production Operations Checklist](https://www.mongodb.com/docs/manual/administration/production-checklist-operations/) documentation recommends setting it to 102400, so let's do it.

```
echo 102400 | sudo tee /proc/sys/vm/max_map_count
#Persist across reboots
echo vm.max_map_count=102400 | sudo tee -a /etc/sysctl.conf
```

Restart MongoDB using `sysctl restart mongod`, then connect with `mongosh` again and verify the `max_map_count` warning is no longer displayed:

```
graeme@pi5PIOS:~ $ sudo systemctl restart mongod
graeme@pi5PIOS:~ $ mongosh
Current Mongosh Log ID:	65a011a4cbbd56fd63aafa0e
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.1
Using MongoDB:		7.0.5
Using Mongosh:		2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2024-01-11T09:04:43.178-07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

test> 
```

Great — we can now deal with the access control warning and, as we said before, this one is important. 

By default, MongoDB is installed to allow anyone access to the database without authentication, but only from the device on which it is running. This means that right now, we can only access it from the Raspberry Pi itself. That might be fine if all access is from applications running on the same device, as could well be the case with deployments on something like a Raspberry Pi. In most cases, though, we will want to open up network access to MongoDB, and we will certainly want to restrict access to only authenticated users.

Let's start by adding a user. Using the `mongosh` shell, run the following command:

```
use admin
db.createUser( { user: "admin",
    pwd: "YOURPASSWORDGOESHERE",
    roles: [ "userAdminAnyDatabase",
             "dbAdminAnyDatabase",
             "readWriteAnyDatabase"] } )`
```

Replace YOURPASSWORDGOESHERE with an actual password (all the usual recommendations about password complexity and length apply). The roles granted to user `admin` by this command give them access to all data and allows them to administer other users, so keep that password secure. 

Now we'll modify MongoDB's configuration file to tell it to enforce user authentication and to listen for connections on all of the Pi's network adaptors (rather than the default of listening only on it's internal loopback adaptor).

Using your preferred editor, modify `/etc/mongod.conf`. You need to change the `bindIp` setting from 127.0.0.1 to 0.0.0.0 (keep `port` set to 27017), and you need to uncomment the `security:` entry and add a new value under it, `authorization: enabled`:

```
net:
  port: 27017
  bindIp: 0.0.0.0

security:
  authorization: enabled
```
Note this is a YAML file, so the indentation is important.

Restart MongoDB once again and connect with `mongosh` — now, there should be no warnings:

```
graeme@pi5PIOS:~ $ sudo systemctl restart mongod
graeme@pi5PIOS:~ $ mongosh
Current Mongosh Log ID:	65a01ab52a2e9d6bb7c7a3f4
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.1
Using MongoDB:		7.0.5
Using Mongosh:		2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

test>
```

> It's worth pointing out at this point that what we've done is  open up access to MongoDB from any device that can establish a network connection to your Raspberry Pi. I'm assuming you are running on a home or office network with a firewall between you and the open internet. Pi OS itself does not have any firewall protections enabled by default. If you want to add them, [`ufw`](https://help.ubuntu.com/community/UFW) is a pretty good option. Suffice it to say, it's almost _never_ a good idea to expose a database server to the open internet, and certainly not one without authentication enabled. You will also want to enable TLS encryption if you're deploying on, or enabling access from, anything other than your home network. Check out the [MongoDB security checklist](https://www.mongodb.com/docs/manual/administration/security-checklist/) for more security advice.

To test network connectivity and authentication, move to another computer with `mongosh` installed (I'm using my Mac laptop), and attempt to connect to MongoDB on your Pi. We'll do this twice: once using an anonymous login and once using the credentials for the `admin` user we created. On both attempts, we'll attempt to run a command to list all databases and verify the anonymous connection is blocked from doing so:

```
graeme@M-YYV2WV29DD ~ % mongosh --host 10.0.0.191
Current Mongosh Log ID:	65a01c72db8f065eddfc3e9b
Connecting to:		mongodb://10.0.0.191:27017/?directConnection=true&appName=mongosh+2.1.1
Using MongoDB:		7.0.5
Using Mongosh:		2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

test> db.adminCommand({listDatabases: 1})
MongoServerError: Command listDatabases requires authentication
```

```
graeme@M-YYV2WV29DD ~ % mongosh --host 10.0.0.191 -u "admin"
Enter password: ********
Current Mongosh Log ID:	65a01e554a71d545c503bc2e
Connecting to:		mongodb://<credentials>@10.0.0.191:27017/?directConnection=true&appName=mongosh+2.1.1
Using MongoDB:		7.0.5
Using Mongosh:		2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

test> db.adminCommand({listDatabases: 1})
{
  databases: [
    { name: 'admin', sizeOnDisk: Long('135168'), empty: false },
    { name: 'config', sizeOnDisk: Long('110592'), empty: false },
    { name: 'local', sizeOnDisk: Long('73728'), empty: false }
  ],
  totalSize: Long('319488'),
  totalSizeMb: Long('0'),
  ok: 1
}
```

**_Congratulations_** — you now have a running deployment of the latest version of MongoDB on your Raspberry Pi. Want to use [time-series](https://www.mongodb.com/docs/manual/core/timeseries-collections/#time-series) and [clustered](https://www.mongodb.com/docs/manual/core/clustered-collections/#clustered-collections) collections for your home IoT project? We got ya. Want to keep your data secure using state-of-the-art [queryable encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption/#queryable-encryption)? We got ya too. So go, have fun, create something amazing, and tell us about it in the comments.