In last article I have described how to install 64-bit Rapberry Pi operation system, Docker and Docker compose. Now it is time to install Mongo DB database that can be installed only on 64-bit system. I will use official Mongo DB Docker image from Docker hub for ARM 64 architecture.
MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).
Install Robo 3T - Mongo DB client
First of all need to install client for Mongo DB that will connect to database. I recommend to use Robo 3T. It has versions for Windows, Mac and Linux operating systems and is freeware. If you have Windows this should not be a problem to download exe file and install program. For Linux it can be little more complicated.
For Linux first of all download file robo3t-1.4.1-linux-x86_64-122dbd9.tar.gz from Robo 3T download page. File name can be different in case new version is released. Then switch to directory where this file is saved
1. Enter following commands
tar -xvzf robo3t-1.4.1-linux-x86_64-122dbd9.tar.gz sudo mkdir /usr/local/bin/robo3t sudo mv robo3t-1.4.1-linux-x86_64-122dbd9/* /usr/local/bin/robo3t cd /usr/local/bin/robo3t/bin sudo chmod +x robo3t sudo nano ~/.bashrc
2. Add the following line to the end of .bashrc file
3. Save and close file, reload using this command
4. Now can start Robo 3T using terminal
If it is working, then installation is complete. Next step is to install Mongo DB server.
Install Mongo DB server
As we use Docker and Docker compose for Mongo DB server, create new yml file
Base configuration required to run container is
version: '3.7' services: mongodb: container_name: mongodb image: mongo:latest restart: unless-stopped environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: rootpassword ports: - 27017:27017 volumes: - /home/pi/docker-volumes/mongodb:/data/db
- MONGO_INITDB_ROOT_USERNAME - parameter to specify root user name
- MONGO_INITDB_ROOT_PASSWORD - parameter to specify root user password
- volumes - file path where Mongo DB data files will be stored
All other settings can leave as they are in this example.
Now can run container
docker-compose up -d
Now can try to connect to database using Robo 3T application.
- Start Robo 3T
- Add new connection to database as showed on screenshots
On first tab specify any name for connection and IP address of Raspberry Pi with Mongo DB. On second tab specify user name and password. Then save connection.
That's all. Connect to Mongo DB and then can create new database, collections, indexes, etc.
This is one more way how to use Raspberry Pi computer. Hosting database for small project on Raspberry Pi has many advantages: you have not to pay for hosting, fully control database and simply this is cool that serious software can be run on such small hardware! Of course on high load database will require more powerful hardware, but for education, experiments, small projects or just for fun it is good enough.