You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
// Create your POCO classpublicclassCustomer{publicintId{get;set;}publicstringName{get;set;}publicintAge{get;set;}publicstring[]Phones{get;set;}publicboolIsActive{get;set;}}// Open database (or create if doesn't exist)using(vardb=newLiteDatabase(@"MyData.db")){// Get customer collectionvarcol=db.GetCollection<Customer>("customers");// Create your new customer instancevarcustomer=newCustomer{Name="John Doe",Phones=newstring[]{"8000-0000","9000-0000"},Age=39,IsActive=true};// Create unique index in Name fieldcol.EnsureIndex(x =>x.Name,true);// Insert new customer document (Id will be auto-incremented)col.Insert(customer);// Update a document inside a collectioncustomer.Name="Joana Doe";col.Update(customer);// Use LINQ to query documents (with no index)varresults=col.Find(x =>x.Age>20);}
Using fluent mapper and cross document reference for more complex data models
// DbRef to cross referencespublicclassOrder{publicObjectIdId{get;set;}publicDateTimeOrderDate{get;set;}publicAddressShippingAddress{get;set;}publicCustomerCustomer{get;set;}publicList<Product>Products{get;set;}}// Re-use mapper from global instancevarmapper=BsonMapper.Global;// "Products" and "Customer" are from other collections (not embedded document)mapper.Entity<Order>().DbRef(x =>x.Customer,"customers")// 1 to 1/0 reference.DbRef(x =>x.Products,"products")// 1 to Many reference.Field(x =>x.ShippingAddress,"addr");// Embedded sub documentusing(vardb=newLiteDatabase("MyOrderDatafile.db")){varorders=db.GetCollection<Order>("orders");// When query Order, includes referencesvarquery=orders.Include(x =>x.Customer).Include(x =>x.Products)// 1 to many reference.Find(x =>x.OrderDate<=DateTime.Now);// Each instance of Order will load Customer/Products referencesforeach(varorderinquery){varname=order.Customer.Name;
...}}