I have been looking around for a compact embedded NoSQL database library for .NET, to use as the back-end of my “iLexicon” system. “iLexicon” is written in Lisp and Prolog (I have written a few articles on it before). At present, the entire dictionary component (containing over 300,000 word entries) is resident in memory, and the idea is to move this to a reasonably fast persistent store.
There are many NoSQL databases for .NET. I briefly explored SiaqODB, Ninja Database Pro, UnQLite, and LiteDB and finally chose LiteDB.
Installing LiteDB
Installation is straightforward. Create a project in Visual Studio (I used VS 2019 ver 16.8.5) and use NuGet Package Manager to install the package as described here.
This creates a separate sub-directory under the project for the package, and adds the correct reference.
Working with the DB Engine
There are two ways to populate the database. One is to define appropriate classes to model the dictionary entries and use instances of these types to store in the DB. The other is to use “BsonDocument” directly and store the data as “JSON” entries. The latter is schema-less and can be convenient in some cases. I tried both.
Let us create some sample entries from the above:
We are now ready to insert the data into the database. For each type of entry (basic word, emotion word, pronoun, etc.), we need to create a “collection” first.
You can see that I am inserting three words in the category of “pronouns” directly using “BsonDocument” without creating a class, unlike WordDef and EmotionWord.
LiteDB Studio
One additional benefit of using LiteDB is that there is also the “LiteDB Studio” that you can install (actually, build from the sources) separately. It allows you to connect to a local database and manage it using a nice UI.
First we have to connect to the local data store:
We can double click on the different collections and execute the default query to fetch the data in that collection.
Overall, I am quite satisfied with LiteDB. It is easy to use, flexible and seems to have acceptable performance. I plan to try it out with the complete iLexicon data in the next couple of weeks, and see how it interfaces with my Prolog NLP parser.
The sample C# source code is here.
Have a nice weekend!
Recent Comments