by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:53
    pejtersen labeled #1756
  • 12:53
    pejtersen opened #1756
  • 07:48
    zandam-xrn commented #1498
  • Jul 13 15:49
    lbnascimento closed #1728
  • Jul 13 15:33
    lbnascimento closed #1738
  • Jul 13 15:33
    lbnascimento closed #1739
  • Jul 13 15:32
    lbnascimento closed #1744
  • Jul 13 15:32
    lbnascimento closed #1746
  • Jul 13 15:19
    lbnascimento commented #1750
  • Jul 13 15:09
    lbnascimento closed #1751
  • Jul 13 15:09
    lbnascimento closed #1752
  • Jul 13 15:09
    lbnascimento closed #1755
  • Jul 10 18:45
    lbnascimento synchronize #1726
  • Jul 10 18:45

    lbnascimento on master

    Revert "Fixed member mapping fo… (compare)

  • Jul 10 16:32
    stephenhauck commented #1755
  • Jul 10 15:22
    lbnascimento commented #1755
  • Jul 10 15:09
    nightroman commented #1755
  • Jul 10 15:01
    lbnascimento commented #1753
  • Jul 10 14:53
    lbnascimento commented #1755
  • Jul 10 14:38
    stephenhauck commented #1751
Leonardo Nascimento
@lbnascimento
@alex-fomin I believe you should try just using the datafile regularly, without rebuilding it (empty space from shrunk records will be reused lated). And if it becomes an issue, you'd have to think of an workaround (somethink like what I suggested: only inserting the records in the datafile after they've been shrunk)
Alex Fomin
@alex-fomin
Ok, thank you!
Helmut Wahrmann
@hwahrmann
Anyone having LiteDBDirectory running? current Nuget version seems not to be compatible with V5
Chase Q. Aucoin
@chaseaucoin
I see AVG and COUNT in the documentation, is there a summation function?
Leonardo Nascimento
@lbnascimento
@chaseaucoin Yes, the full list of functions can be checked at http://www.litedb.org/api/functions/
Chase Q. Aucoin
@chaseaucoin
Ah, thank you! missed that page somehow
Chase Q. Aucoin
@chaseaucoin
If putting an API on top of this is it better to have it as a singleton or to open a connection per request?
Never mind I saw FutureTD's question
offengenden
@offengenden
Cannot delete and update by my id
Timothy
@timothyparez
I have a collection and I find an entry in it var entry = collection.FindOne(h => h.Id == id) and then I would like to delete that entry collection.Delete(entry) but there is no such overload, I only see one signature for Delete which takes an BsonValue Id
This differs from the documentation online
so how can I delete that entry?
Leonardo Nascimento
@lbnascimento
@timothyparez You have the id, which you used to call FindOne, you can use the same id calling collection.Delete(id)
Timothy
@timothyparez
@lbnascimento no FindOne returns an instance of FileHashEntry which is the class of the instances I store in the database
image.png
or I am missing the other overloads for some reason
image.png
Timothy
@timothyparez
I do not see any other overloads. So I am getting back an instance of FileHashEntry and it is expecting a BsonValue
Target Framework: Mono 6.8.3 in a Godot 3.2.1 project
Argument 1: cannot convert from 'FileHashEntry' to 'LiteDB.BsonValue'
Assembly LiteDB, Version=5.0.8.0
Leonardo Nascimento
@lbnascimento
@timothyparez You used an id in the FindOne call (id in the lambda expression inside FindOne)
You can use the same id variable when calling Delete: collection.Delete(id)
You can also use the entry id: collection.Delete(entry.Id)
Timothy
@timothyparez
image.png
It does not have an Id property
Leonardo Nascimento
@lbnascimento
@timothyparez If that's the case, then you should use DeleteMany
Something like: hashes.DeleteMany(h => h.Hash == hash)
This is less efficient than deleting by id (for a collection with n documents, this is O(n) instead of O(log n))
Leonardo Nascimento
@lbnascimento
(unless the field Hash is indexed)
Leonardo Nascimento
@lbnascimento
Also, while LiteDB allows you to store classes without an Id field, this is not recommended because you'll have to resort to various workarounds (like using DeleteMany instead of Delete)
So I would recommend that you added an Id field to your class. If you can't (if it's an external class) and Hash is an unique identifier of every file (which I believe it is), you could use our fluent mapper to set it as the Id field: BsonMapper.Global.Entity<FileHashEntry>().Id(x => x.Hash)
Timothy
@timothyparez
@lbnascimento will have a look thnx!
Toorah
@Toorah

Hi, I have a couple of questions, as I couldn't find a direct answer in the docs.

1) Does LiteDB support multi-threading and do I need to pay attention to anything special when using it multi-threaded?
2) After getting a ILiteCollection with LiteDatabase.GetCollection(), there is the method ILiteCollection.Upsert(), I suppose it uses the ID to figure out whether it should be added or updated in the collection. There are Bulk operations for Insert & Update but not for Upsert. What would be a good way to handle this? I am using LiteDB as a save-file. Objects are only "written" to the Collection when explicitly saving, so I would have to track objects that already exist and objects that haven't been saved yet, and call BulUpdate on existing and BulkInsert on new ones, as calling Upsert in a loop over and over for each object might not be a good idea, right?
3) I am not exactly understanding the purpose for the .EnsureIndex() method. This is not what creates the ID values, correct? It's meant to speedup searching for entries in a collection via fields that were marked with .EnsureIndex(), or am I wrong?

Thanks for any answers in advance

Leonardo Nascimento
@lbnascimento
@Toorah 1) LiteDB supports multi-threaded use, you should be fine by sharing an instance of LiteDatabase or LiteCollection between threads
Toorah
@Toorah
and if I handle LiteDB entirely in a single, separate thread it should be fine, right?
Leonardo Nascimento
@lbnascimento
Yes, it is fine too
Toorah
@Toorah
Perfect, thank you.
Leonardo Nascimento
@lbnascimento
2) All the bulk methods do is to run all the inserts/updates in a single transaction (instead of one transaction per operation, which is what calling the methods directly does). You can achieve the same effect for Upsert by calling ILiteDatabase.BeginTrans(), upserting your objects with a loop and calling ILiteDatabase.Commit() after you're done. This will be a lot faster that inserting one object per transaction (which is the default behavior).
Toorah
@Toorah
This means I can have a single List of objects, with pre-existing and new objects mixed, and call Upsert on each in a loop and LiteDB will Insert/Update as needed, right?
Leonardo Nascimento
@lbnascimento
Yes, as long as the id is correct, it will determine whether to insert or update the object.
Toorah
@Toorah
Great :)
Leonardo Nascimento
@lbnascimento
3) You're correct, EnsureIndex() is used to create an index over a field, which will make queries over that field faster.
Toorah
@Toorah
Can I use EnsureIndex on multiple fields? Like: ID, Name, Location
doing 3 separate calls on EnsureIndex()
related question: Do I have to call EnsureIndex() several times, for example, should I call it again after adding objects to the collection?
Or is it enough to call it once at the beginning, and LiteDB will handle the rest, even new objects
Leonardo Nascimento
@lbnascimento
@Toorah Yes, you can create an index over whatever fields you want (no need to run EnsureField() over the id field, it is always indexed).
And you should call EnsureIndex() only once. This will index pre-existing objects and will also index anything that is inserted/updated in the collection in the future.
Toorah
@Toorah
Great, thank you very much