# LiteDB — Serverless Embedded NoSQL Database for .NET > A lightweight, zero-configuration embedded NoSQL database written in C# that stores data in a single file, designed for small desktop, mobile, and web applications. ## Install Save in your project root: # LiteDB — Serverless Embedded NoSQL Database for .NET ## Quick Use ```bash dotnet add package LiteDB ``` ```csharp using LiteDB; using var db = new LiteDatabase("MyData.db"); var col = db.GetCollection("customers"); col.Insert(new Customer { Name = "Alice", Age = 30 }); var results = col.Find(x => x.Age > 25); ``` ## Introduction LiteDB is a serverless, zero-configuration embedded NoSQL database for .NET. It stores all data in a single file using a document model similar to MongoDB, making it a practical choice for desktop apps, mobile projects, and small web services that need local persistence without running a separate database server. ## What LiteDB Does - Stores documents as BSON in a single portable data file - Provides LINQ-style queries and a SQL-like query language - Supports indexing, transactions, and encryption at rest - Runs in-process with no external dependencies or background services - Offers a cross-platform .NET Standard 2.0 library ## Architecture Overview LiteDB uses a page-based storage engine that manages data, indexes, and metadata in one file. Documents are serialized to BSON and organized into collections. A write-ahead log handles crash recovery, and a B-tree index structure supports fast lookups. The engine runs inside the host process, using file-level locking for concurrent access. ## Self-Hosting & Configuration - Add the NuGet package to any .NET project — no installation or server needed - Specify a file path to create or open a database; the file is created automatically - Enable password-based AES encryption by passing a connection string with a password parameter - Configure journaling, cache size, and timeout through connection string options - Use the LiteDB.Studio desktop tool for visual data browsing and query testing ## Key Features - Single-file storage with ACID transactions - Thread-safe shared and exclusive access modes for multi-threaded apps - Full-text search with custom analyzers - File and stream storage via a built-in GridFS-like API - Schema-free document model with automatic ID generation ## Comparison with Similar Tools - **SQLite** — relational and SQL-based; LiteDB is document-oriented with LINQ support - **Realm** — targets mobile with live objects; LiteDB is a simpler file-based store for .NET - **RavenDB** — full client-server document DB; LiteDB is embedded and zero-config - **NeDB** — embedded DB for Node.js; LiteDB serves the same role in the .NET ecosystem - **MongoDB** — networked, horizontally scalable; LiteDB is for single-process local use ## FAQ **Q: How large can a LiteDB database grow?** A: There is no hard-coded size limit. Databases of several gigabytes work fine, though it is designed for small-to-medium data sets rather than big data workloads. **Q: Is LiteDB safe for concurrent writes from multiple threads?** A: Yes. It supports shared and exclusive locking modes and handles concurrent access within a single process. Multi-process access to the same file requires external coordination. **Q: Can I use LiteDB in a Blazor or MAUI application?** A: Yes. It runs on .NET Standard 2.0, so it works in Blazor Server, MAUI, Xamarin, and any other compatible .NET runtime. **Q: Does LiteDB support migrations or schema changes?** A: Because it is schema-free, adding new fields does not require migrations. Renaming or restructuring fields can be done programmatically at the application level. ## Sources - https://github.com/mbdavid/LiteDB - https://www.litedb.org/ --- Source: https://tokrepo.com/en/workflows/asset-0df5f051 Author: AI Open Source