gitmyhub

LiteDB

C# ★ 9.4k updated 13d ago

LiteDB - A .NET NoSQL Document Store in a single data file

LiteDB is a tiny embedded NoSQL document database for .NET apps that stores everything in a single file, no server needed, with a MongoDB-like API, full transactions, encryption, and concurrent read support.

C#.NETNuGetBSONLINQsetup: easycomplexity 2/5

LiteDB is an embedded database for .NET applications, meaning it runs inside your application without needing a separate database server. All data is stored in a single file on disk, similar to how SQLite works for relational data, but LiteDB stores documents rather than tables. It is free and open-source under the MIT license, and the compiled library weighs less than 450 kilobytes.

The API is intentionally similar to MongoDB. You define your data as plain C# classes, and LiteDB handles serializing them into a document format called BSON and back again. You can query documents using LINQ, which is a standard C# query syntax, or using SQL-like commands if you prefer. Version 5 introduced a new storage engine that allows multiple readers at the same time and write locks that only block at the collection level rather than the whole database, which improves performance for concurrent access.

LiteDB supports full transactions, meaning a write operation either completes fully or is rolled back, and it writes a log file to recover data after an unexpected crash. Optionally, the database file can be encrypted using AES. There is also support for storing binary files and streams in the database directly, similar to how MongoDB handles large file storage.

The README suggests LiteDB is best suited for desktop applications, small web applications, and cases where you want one database file per user or account. There is a separate graphical tool called LiteDB Studio for browsing and querying the database without writing code. The library is available as a NuGet package with a straightforward install command.

Where it fits