Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jan 22 22:37
    leandromolina commented #1096
  • Jan 22 15:56
    mbdavid commented #1906
  • Jan 22 15:56
    mbdavid synchronize #1726
  • Jan 22 15:56

    mbdavid on master

    Fixed issue #1772: Unfortunatel… Merge pull request #1906 from f… (compare)

  • Jan 22 15:56
    mbdavid closed #1906
  • Jan 22 15:01
    frankneumann commented #1772
  • Jan 22 14:57
    mbdavid commented #1772
  • Jan 21 16:20
    dkalnauz commented #1915
  • Jan 20 15:13
    laurenceSaes commented #1925
  • Jan 20 14:55
    laurenceSaes commented #1925
  • Jan 20 14:36
    laurenceSaes labeled #1925
  • Jan 20 14:36
    laurenceSaes opened #1925
  • Jan 19 10:00
    siquylee commented #1915
  • Jan 18 22:55
    mchudinov commented #1162
  • Jan 18 22:52
    mchudinov commented #1162
  • Jan 18 13:56
    Zeke133 edited #1924
  • Jan 18 13:55
    Zeke133 labeled #1924
  • Jan 18 13:55
    Zeke133 opened #1924
  • Jan 15 18:15
    tivial19 opened #1923
  • Jan 15 11:34
    mirasrael edited #1922
What is the cost of a new LiteDatabase("file") ? And what is the recommended life time for the LiteDatabase instance? would it be ok to keep it opened during the application lifetime?
Hank G
I use it for the life of the application since it is the backbone of the persistence layer.
thanks @HankG. in my case it's not a good idea because I'm accessing the data from multiple processes. most of the time they don't overlap, but I did get an exception when the db file was locked
Hank G
Yeah anything with multiple processes I'm going to jump to Mongo for a Document database
or Postgres for relational
@mbdavid Hi,
@lbnascimento explained well how LiteDB works under the hood,
Since I made a big refactor and all my queries are based on predicates, I am stuck for more than 3 weeks, can someone help me to find a solution for this situation,
Did someone manage how to combine two predicate and use it in LiteDB ?
thanks developers ---- issue: #1829
Hello - We have a system where we need to persist large XML documents (~10-20MB each). I noticed that the document size limit is 1MB. Does this rule out LiteDB as a good choice for persistence?
Leonardo Nascimento
@Chadley08 This limit has been increased to 16MB recently. And LiteDB internally uses BSON, which is much more compact than XML or even JSON.
However, you still need to make sure that you won't ever need to store files that use more than 16MB after BSON serialization.
@lbnascimento Thank you! After reviewing the docs a bit more, it looks like I can deserialize my XML file to a domain object, then I'm going to try saving that to the LiteDB as I think it will create a document for each object in the object's hierarchy. Those should be relatively small.
Torben Stallknecht
It might be, that my Googling and reading abilities are crap, but I have been unable to find the answer. What, if any, limit is there to the database. I get that Documents are 1MB(16MB in newer versions?). There is a limit of 8000 bytes for collection names, which in essens limits the amount of collections. So, let's say I have 1 collection in my database. How many 1 MB documents can it store?
Leonardo Nascimento
@stallemanden There's no limit for number of documents in a collection.
Hello. My TimeSpan? store as {"$numberLong":"600000000"}, but when i try deserialize them i get exception: cant cast long to TimeSpan. But if i use non-nullable TimeSpan all is ok. What am I doing wrong?
Leonardo Nascimento
@SKProCH_gitlab What version of LiteDB are you using?

Is it possible to use the following expression with LiteDB?

return maintenanceAssetCollection.UpdateMany(_ =>
            new MaintainableAssetEntity()
                AttributeDatumEntities = new List<IAttributeDatumEntity>(),
                Id = _.Id,
                LocationEntity = _.LocationEntity,
                NetworkId = _.NetworkId
            _ => _.NetworkId == networkId);

I keep getting a runtime NotSupported exception. When I change the list assignment to null it works.

Ah, I changed the code to this and it seemed to work:

return maintenanceAssetCollection.UpdateMany(_ =>
            new MaintainableAssetEntity()
                AttributeDatumEntities = new List<IAttributeDatumEntity>() { },
                Id = _.Id,
                LocationEntity = _.LocationEntity,
                NetworkId = _.NetworkId
            _ => _.NetworkId == networkId);

Note the curly brackets in the new list expression are the change.

Osama Al Banna

Hi, I can not find any way to use expressions and functions: https://www.litedb.org/api/functions/ https://www.litedb.org/docs/expressions/
how can I do that?
suppose I have a collection Called
FinancialContractCollection contains Contracts

 public class FinancialContract : ReactiveObject, IHotHostReloaded<FinancialContract>
        [BsonId] public ObjectId Id { get; set; }

        public string PersonName { get; set; }
        public string PersonIdNumber { get; set; }
        public DateTime StartDate { get; set; }

How can I get the recent Contract with depends on StartDate by using Functions | Expressions

The problem is i can not find anything in the documentation descripe how to use it, the only example is with indices

And take this example from expressions page

    SELECT { upper_titles: ARRAY(UPPER($.Books[*].Title)) } WHERE $.Name LIKE "John%"

How can i execute this from c# ??

Please Helpe me.

Mike Photo Vintage
Operation could destabilize the runtime
When I create the db or insert data I get this error: "Operation could destabilize the runtime".
WebAPi hosted, I have write permissions, a test file is written regularly.

Hi everyone

I'm trying to use LiteDB (net45) in Unity 2019 targeting an ARM device. The sample application to perform CRUD operations works fine in the editor but in the device I'm getting this exception:

System.NotSupportedException: Invalid BsonExpression when converted from Linq expression: x => x.Name - `$.Name` ---> System.TypeInitializationException: The type initializer for 'LiteDB.BsonExpression' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: method

I did some googling and found a stack overflow question asking about this, in which the one answer states that this could be due to missing dependencies. However, I am using the .NETFramework 4.5 DLL which according to the NuGet page does not have any dependencies.

Has anyone faced this issue? If so can someone let me know how I can address this?

i need a api key !!
My log file grows indefinitely it seems on Azure
what a weird issue
Tim Moore

In LiteDB 5, what does the bool return value mean with Upsert on a LiteCollection? I can't find documentation saying what it does.

I'd normally assume false means it didn't apply changes, but on first call it inserts a document and returns true, and second call with document with same ID and different values, it updates the record but returns false.

I've got existing code that assumed true just meant success and if that's not the case I've got some bugs there. Although that was with LiteDB 4, and I'm migrating to 5.

Hello, I'd like to ask what the return value of the rebuild() function is supposed to represent?
Hey there, dumb question - is there a simple way to serialize my entire database into a JSON string?

Sometimes, with LiteDb 5, I will need to trigger Upsert twice for it to be saved into the database. I can't replicate this problem, sometime it works, sometime it wont'.

Can this be a code racing issues?

Any idea why this is happening?

Najem Azdufal (Nesh)
Hello togehter, i have updated an older Application from Version 3 to 5. My Idea was to speedup some queries by using projection. What i found out, that it takes more time to receive a projected Result than getting the whole document. ist this right?
How do I query an index for unique values?
I'm having an issue trying to get the autoID mapping working in litedb 5.0.9
public class CharacterTraits
        public int Index { get; set; }
        public uint CharacterId { get; set; }
        public uint TraitId { get; set; }
        public SpoilerLevel SpoilerLevel { get; set; }
I then have a List<CharacterTraits> characterTraitsList = new List<CharacterTraits>(); with multiple elements in it. But when I run the following command (dbCharTraits.InsertBulk(CharacterTraitsList);), I get the following error.
""Cannot insert duplicate key in unique index '_id'. The duplicate value is '1'.""
Damian Płaza

Hi! I've got a question about performance - I am using FindByOne method on my collection, but it seems like it takes some to load the document from the database. Here's my F# implementation of GetById repository

member this.GetById (id: string): 'a option =
            let mapper = FSharpBsonMapper()
            use db = new LiteDatabase(connectionString, mapper)
            let collection = db.GetCollection<BsonDocument>(collectionName)
            let queryResult = collection.FindById (BsonValue(id))

            Option.fromBson queryResult

As I understood, _id is indexed automatically so it should be rather fast, isn't it? My DB file on the disc has approx. 30MB.

I just want to understand what happens that it's slow :-) I would appreciate any help/clarification

Hi All, I need a help. I have updated LiteDB package in one of my projects from 0.9 to the latest version. All is ok but error:
var files = db.FileStorage.Find(strResource); // <----------------- no FileStorage
foreach (var fi in files)
var stream = fi.OpenRead();
return stream;
How to fix it ?
Another question: after upgrade nuget from 0.9 to the latest one my app cannot open the existing database
Message = "File is not a valid LiteDB database format or contains a invalid password."
How to fix it?
Torben Stallknecht
I am not sure, but I would think, that you need to upgrade the DB step-by-step.
I assume, that the upgrade to v5 requires a certain version to be able to upgrade.
You are right, but it is not possible to upgrade v 0.9 to any up version. I have tried to use "upgrade=true" in connection string - does not work. LiteDB studio does not understand this db format too.
Torben Stallknecht
I had a look at the version release notes. It states for version 1.0.0: To prepare LiteDB to future, version 1.x break compatibility with 0.x. Small external changes, but very important to make a better source structure:
So i guess the only way is to write some sort of conversion program for your data, to get it to a newer version.
Yes, it is one way ....
Another problem using the v5 in comparison with 0.9.
But in the v5 in gives me exception:
{"Unexpected token \\ in position 7."}
How to find this key in the db?
Torben Stallknecht
@win32nipuh I must admit, I am not that sure about it, but i suspect, that the reason your code is not working as intended is, the big change mentioned before. I have not worked with earlier versions. Anyway, from what I can see, the reason for the error, is the "\" in your string.