litedb-org /LiteDB

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

★ 9,492⑂ 1,323👁 279⑃ 617● 2,446▤ 63
C#MITCreated 2014-08-25www.litedb.org
Download: v5.0.21v5.0.21 ↓5.0.212024-07-05
+0
Daily
9,492
stars
1,323
forks
279
watchers
617
prs
2,446
issues
63
releases

README

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



 



LiteDB is a small, fast and lightweight .NET NoSQL embedded database. 

- Serverless NoSQL Document Store
- Simple API, similar to MongoDB
- 100% C code for .NET 4.5 / NETStandard 1.3/2.0 in a single DLL (less than 450kb)
- Thread-safe
- ACID with full transaction support
- Data recovery after write failure (WAL log file)
- ~~Datafile encryption using DES (AES) cryptography~~ This implemention is currently not secure, DO NOT USE.
- Map your POCO classes to BsonDocument using attributes or fluent mapper API
- Store files and stream data (like GridFS in MongoDB)
- Single data file storage (like SQLite)
- Index document fields for fast search
- LINQ support for queries
- SQL-Like commands to access/transform data
- LiteDB Studio - Nice UI for data access 
- Open source and free for everyone - including commercial use
- Install from NuGet: Install-Package LiteDB


 New v5

- New storage engine
- No locks for read operations (multiple readers)
- Write locks per collection (multiple writers)
- Internal/System collections 
- New SQL-Like Syntax
- New query engine (support projection, sort, filter, query)
- Partial document load (root level)
- and much, much more!

 Lite.Studio

New UI to manage and visualize your database:


!LiteDB.Studio

 Documentation

Visit the Wiki for full documentation. For simplified chinese version, check here.

 LiteDB Community

Help LiteDB grow its user community by answering this simple survey

 How to use LiteDB

A quick example for storing and searching documents:

C
// Create your POCO class
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string[] Phones { get; set; }
    public bool IsActive { get; set; }
}

// Open database (or create if doesn't exist)
using(var db = new LiteDatabase(@"MyData.db"))
{
    // Get customer collection
    var col = db.GetCollection("customers");

    // Create your new customer instance
    var customer = new Customer
    { 
        Name = "John Doe", 
        Phones = new string[] { "8000-0000", "9000-0000" }, 
        Age = 39,
        IsActive = true
    };

    // Create unique index in Name field
    col.EnsureIndex(x = x.Name, true);

    // Insert new customer document (Id will be auto-incremented)
    col.Insert(customer);

    // Update a document inside a collection
    customer.Name = "Joana Doe";

    col.Update(customer);

    // Use LINQ to query documents (with no index)
    var results = col.Find(x = x.Age  20);
}


 BSON serialization

If you need direct access to raw BSON, BsonSerializer exposes overloads that write into caller-supplied Memory or IBufferWriter instances. This allows applications to reuse buffers from pools without forcing an intermediate array allocation. The Memory must be backed by a managed array. The IBufferWriter overload is available in the net8.0 and net10.0 builds, but is omitted from the nets

Top issues

Discussions

Latest release

v5.0.21 v5.0.21 2024-07-05
What's Changed
 Fix 2265 Stackoverflow when Self reference by @JKamsker in https://github.com/mbdavid/LiteDB/pull/2493
 Add-Badges by @JKamsker in https://github.com/mbdavid/LiteDB/pull/2496
 Fix crash with stack trace by @Pysis868 in https://github.com/mbdavid/LiteDB/pull/2476
 Fix LiteFileStream.SetReadStreamPosition by @SpaceCheetah in https://github.com/mbdavid/LiteDB/pull/2459
 Addresses issue of upgrading from v4.x databases in LiteDB versions 5.0.18-5.0.20 by @jdtkw in https://github.com/mbdavid/LiteDB/pull/2499
 Don't capture synchronization context in DiskWriterQueue by @alexber

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON