What's new

New expression support on index definition. You can index any field of your document

Map you entity class using Attributes or Fluent api

LiteRepository class to simple and easy access

DbRef for cross document reference

LiteDB has a big inspiration on MongoDB. I tried to create a database thats works like MongoDB, but in a very small scale using only most important features for small applications. If you know MongoDB, you already know LiteDB.

Where to use?

Quick Starts

Let´s see some conecpts about LiteDB dabatase and data structure. If you need more documents, you can read Github Wiki documentation.

Documents

LiteDB works with documents to store and retrive data inside data file. Your document definition can be a POCO class or BsonDocument class. In both case, LiteDB will convert your document in a BSON format to store inside disk.

BSON is a Binary JSON, a serialization for store data objects as binary array. In BSON, we have more data types than JSON, like DateTime, Guid and ObjectId.

Documents using POCO class

POCO class are simple C# classes using only get/set properties. It's the best way to create a strong typed documents. Your class must have an identifier property. You can use Id named property, <ClassName>Id or decorate any property with [BsonId] attribute.

Collections - the store

LiteDB organize documents in stores (called in LiteDB as collections). Each collection has a unique name and contains documents with same schema/type. You can get a strong typed collection or a generic BsonDocument collections, using GetCollection from LiteDatabase instance.

Fail tolerance - Journaling/Recovery

LiteDB uses on-disk journal file to guarantee write operation durability. This mean that before a write operation, all dirty pages will be first writed in same file before write on main datafile (use end of file to store clear pages).

This feature can be disabled on connection string - runs faster but if has a crash on write operation your datafile can be inconsistent.

Working with files - FileStorage

Sametimes we need store files in database. For this, LiteDB has a special FileStorage collection to store files without document size limit (file limit is 2Gb per file). It's works like MongoDB GridFS.

LiteDB.Shell

LiteDB contains a shell console application included. This shell can be used to run commands in datafile without any other application. See below most useful commands. To see all commands, use "help" command.

I have a problem. I have used MongoDB seamlessly in .NET core 2.2 (as microsoft documents provide an example for MongoDB). But I don't know how to use LiteDB in .NET core MVC web application seamlessly.
I am new to .NET and visual studio, and entity framework provider or connection string in configuration files is not clear for LiteDB.
Have you plans for such seamless support?

As Unity's main programming language is C# I was wondering if I could you use LiteDB with my game. For what I've seen it is supposed to work as an ORM. So can it do it?
Greetings and great job. Can you publish your twitter account please?

I have built your source code out of the box using .Net 4.6 and run the LiteDB.Demo in Debug mode. It generates a steady stream of System.IO.IOException errors and finally gives an unhandled exception of type System.AggregateException in mscorlib.dll. This is using Visual Studio Community 2017 Version 15.4.1. Any suggestions would be welcome. Thanks

I'm not sure how much experience you have, but I've been looking at this (sort of thing) myself recently - there seems to be a number of thoughts along the lines of 'dynamic LINQ expression from string'

I havnt tried any of these - for the Article/Blog I'm playing with, I found it suitable for a Func<string, bool=""> Lambda expression to be passed into a 'function', with a default of 'null', and using that 'Lambda' in the .Where() clause.

While 2GB may seem like a lot, it really isn't, not when you're talking about storing some data from an Enterprise CRM. Some files can be as big as 10 or 30GB. It would be really nice if there wasn't a hard 2GB limit. Please let me know if this can be achieved.

I realize I can just save a file to disk and reference it, but I'd like to make everything self contained in a single database file for portability.

I am working on a project that will require a small database, say 50 tables with a few thousand rows each. I started in 2014 and all I could find was Sqlite. It is ok, I have plenty of experience with SQL, but it really was massive overkill and overhead.

I shelved the project for a time and when I came back to it, unsatisfied with the amount of extra work SQL was engendering, I took another Google and found LiteDb.

This is EXACTLY what I was looking for. I bit the bullet and converted all my code to use LiteDb and I have not only not regretted it, it has been a godsend.

As yet, I have not encountered a single issue using it. Granted, I'm doing some pretty basic stuff, CRUD to a small db. Documentation is a bit scarce, but I've never taken very long to figure out how to do something. I supposed those who are already familiar with Mongo have an easier time but I am not complaining about that, the usage is mostly so straightforward not a lot of doc is required.

Thanks to the author for putting something so useful and appropriate out there!

And 5 star is goes to....LiteDB. You are the one Mauricio David. I explore 50-100 nosql solutions and select yours. Because your solution/library is so simple to understand your code very clear also robust enough to achieve many situations about storing data to a single, nosql and serverless file.

Praise is enough and time to criticism Documentation not enough but also not bad too. But samples absolutely not enough. My opinion at least you have to write one sample for one complex scenario.

And i'have five questions for you.

1. I have a simple entity that have int id and string name. I want to use fluent api and point id is primary index and name is unique index. Because of that i write below code;

After registration at some point i write/read my currencies collection (i didn't share these codes because i'm using many patterns like entity, repository, unitofwork etc. and post will be so dirty) and don't receiving any error and see my data.db is created. I used shell to check every currency is write correctly. I see currencies collection is created, inserted data is there also but if i check indexes via db.currencies.indexes i see there is Name index but not unique index. So maybe not today but sooner or later i'll receive an exception. Please help me about that why my index not creating unique like i indicate my mapper.

PS: Also i try to use BsonMapper.Global too but nothing changed.

2. What are you thinking about time series databases. Are you have any plan to write time series version of LiteDB (LiteTSDB)? What is your opinion about that this type databases really useful for especially for financial applications?

3. If my entities have special properties like TimeZonInfo, how can i read/write this properties from/to storage. I have to write converters for this type properties? If so how, please write simple example about it.

4. When subject is data, relations are Inevitable. So could you write example about all relation types, one to one, one to many, many to many.

5. I don't understand usage of EnsureIndex. If i use mapper and specify indexes why i have to call it? Why i have to call it after every insert a record? Am i have to call it after every update & delete operations too? Sometimes you call it after call GetCollection<customer>("Customers"). I'm so confused about usage of it. Please give me a detailed info about it.

Sorry for too long post. Again many thanks for all your effort for develop this incredible library. God bless you!