Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 25 14:22
    tjmoore commented #1881
  • Nov 24 19:55
    tjmoore commented #1881
  • Nov 24 19:51
    tjmoore labeled #1881
  • Nov 24 19:51
    tjmoore opened #1881
  • Nov 24 19:10
    botne commented #1756
  • Nov 23 15:30
    VarunSaiTeja closed #1840
  • Nov 23 08:50
    iliaga commented #955
  • Nov 21 20:38
    3m2n closed #1880
  • Nov 21 20:38
    3m2n edited #1880
  • Nov 21 20:31
    3m2n edited #1880
  • Nov 21 20:29
    3m2n edited #1880
  • Nov 21 20:23
    3m2n labeled #1880
  • Nov 21 20:23
    3m2n opened #1880
  • Nov 20 13:06
    danglingneuron labeled #1879
  • Nov 20 13:06
    danglingneuron opened #1879
  • Nov 18 02:19
    sysmirror closed #1875
  • Nov 18 02:19
    sysmirror commented #1875
  • Nov 17 23:02
    andy10james edited #1878
  • Nov 17 21:00
    mcoge closed #1877
  • Nov 17 21:00
    mcoge commented #1877
Leonardo Nascimento
@lbnascimento
@JbMarchal_twitter LiteDB can be used as an in-memory database by using :memory: as its datafile or by using the LiteDatabase ctor that takes a Stream (you can pass a MemoryStream to it)
raizam
@raizam
thanks @lbnascimento

@raizam You can create an index over a DateTime field or even make it your Id field. Due to the BSON spec, LiteDB only stores dates up to the miliseconds (losing a bit of precision). There is a simple workaround for that though, so let me know if you need help with that.

will the DateTime order be preserved when I'll iterate the records? in both indexed/key scenarios?

Mi.Chi
@AlessioMiky76_twitter
@lbnascimento thanks, i cross fingers, it is a must to have feature ;)
Leonardo Nascimento
@lbnascimento
@raizam Yes, the order will be preserved.
raizam
@raizam
perfect :)
raizam
@raizam
is it possible to get a list of ids without fetching the collection?
Leonardo Nascimento
@lbnascimento
@raizam If you don't have an open LiteCollection, you can use the LiteDatabase.Execute(string command)
@raizam Something like db.Execute("select $._id from collection").ToList(). This will give you a list of BsonDocuments containing the id
@raizam If you wanted to do it all in one command, I would suggest var ids = db.Execute("select $._id from collection").ToEnumerable().Select(doc => doc["_id"].AsInt32).ToList(); (assuming the id is Int32)
raizam
@raizam
I see. I'm storing objects with large binary data, so retrieving BsonDocument would still allocate all the memory needed for the whole documents right?
I guess I should use DbRef
Leonardo Nascimento
@lbnascimento
@raizam Not exactly. LiteDB will still navigate through the documents in the collection (this is something we intend to optimize in future versions), but it will only deserialize the necessary fields.
martinweihrauch
@martinweihrauch
Hello everyone, I am using LiteDB, which I love because of the ease of use and quick deployment at customer's sites. I just have one question: I am using LiteDB for a self-written backup program für Azure blobs. Now, there is a situation, where I would like to "loop" through all database entries of one collection. I only found the possibility to load the entire collection as a List. Is there a possibility of a memory problem, if I have e. g. millions of records, which I want to loop through or do you have some way of caching? Thx
Leonardo Nascimento
@lbnascimento
@martinweihrauch Methods like LiteCollection<T>.Find(...) and LiteCollection<T>.FindAll() return an IEnumerable<T> and documents are only loaded when they're needed. So, you can simply use a foreach loop to iterate through this IEnumerable<T>.
@martinweihrauch However, if you call .ToList() or .ToArray(), then all the documents in the collection will be loaded into memory.
martinweihrauch
@martinweihrauch
@lbnascimento Oh God - thanks so much - not only did I learn how to handle that with LiteDB, but also learnt some more C# today because of you! BTW: are you financially backed somehow for your efforts?
travis-leith
@travis-leith
I've just encountered LiteDb for the first time. Looks cool. I am considering using it but want to check with more experienced users about when not to use it. My app currently has a small user base, but it could grow in the future. Is LiteDb recommended for apps with many concurrent users?
Hank G
@HankG
"Concurrent users" as in one process with many users or "concurrent users" as in multiple applications connecting to the same database?
travis-leith
@travis-leith
@HankG I can probably get away with one process many users for a while at least. Your comment led me to the docs on this topic. I see that one process is preferred if speed is a concern. Reading between the lines my take currently is that LiteDB is super simple and capable for a monolithic application (or at least single process access) that doesn't require horizontal scalability/high availability. Would you agree?
Hank G
@HankG
Think of it as SQLite but a NoSQL document database
the deployment use cases for the two are similar
travis-leith
@travis-leith
makes sense
raizam
@raizam
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
@HankG
I use it for the life of the application since it is the backbone of the persistence layer.
raizam
@raizam
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
@HankG
Yeah anything with multiple processes I'm going to jump to Mongo for a Document database
or Postgres for relational
toumir
@toumir
@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
Chadley08
@Chadley08
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
@lbnascimento
@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.
Chadley08
@Chadley08
@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
@stallemanden
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
@lbnascimento
@stallemanden There's no limit for number of documents in a collection.
SKProCH
@SKProCH_gitlab
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
@lbnascimento
@SKProCH_gitlab What version of LiteDB are you using?
Chadley08
@Chadley08

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
@AlBannaTechno

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
@MikePhotoVinta1_twitter
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.
Vijay
@Vijay-2020

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?

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

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.

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