Quick tutorial-like explanation how I setup a LiteDB database to my Raspberry Pi
Setting up LiteDB on a Raspberry Pi
If you want to skip the setup for my situation, press me. I am not an expert, but learning and experimenting myselfWhat's the point?
I finally got myself a model 3 b+ Raspberry Pi and as I've never worked with a NoSQL database before, I decided to try one out with it. My initial choice was running a MongoDB database inside a docker container.
So I got to work, first setting up the Raspberry Pi. Which was pretty painless as I had hoped, although the update time after the initial installation of the included OS was surprisingly long. The updates took over an hour and I thought it was frozen, but in the end it came through.
Then I installed docker and went on to search a MongoDB image. I ran to an issue that I have not had to think about before. I've always used supported OS architectures when shopping for docker containers. The Raspberry's arm7 was not supported by the image and I could not find an alternative.
So I turned to google in my search for a lightweight NoSQL database and found LiteDB. It seemed to be light enough for my purposes and I'm also learning Dotnet for azure, so it seemed like a good match. I installed Dotnet using the install-dotnet script and began.
Creating the LiteDB database
Creating the basic app
To make my life a bit easier I set up a remote vscode connection for development. The extension was positively easy to setup. I had to start with creating the basic app before getting my hands on the LiteDB, so I created a basic dotnet Console App.
dotnet new console
After that I could go on and install the actual LiteDB dotnet package.
dotnet add package LiteDB --version 5.0.16
And of course ran into some issues.
error: LiteDB -> LiteDB (>= 5.0.16).
info : Package 'LiteDB' is compatible with all the specified frameworks in project '/home/mituuz/LiteDB/LiteDB.csproj'.
error: Value cannot be null. (Parameter 'path1')
Searching a bit looks like clearing the nuget cache might be enough:
dotnet nuget locals all --clear
That didn't work, but I found out that the project cannot have the same name as the package you're trying to install. So I created a new folder named RasLiteDB and a new console app and that fixed the issue. I finally got the LiteDB package installed and ran the hello world Console App successfully.
mituuz@raspberrypi:~/RasLiteDB $ dotnet run
Hello, World!
So now we can create the first object and test the database. I've shared the code here: GitHub under the tag "setup". In the repo I'm first creating the database and the collection if they don't exist and then inserting and querying a single entry.
The LiteDB was really easy to setup and I can start using it with my Raspberry. I'm not sure it is the best option for Raspberry DB, but it seems lightweight and simple to setup. Time will tell.