2

There are two applications,

  • one console application keeps writing data to a litedb database continuously.
  • The other console application reads data and deletes whatever was read
var liteCollection = _liteDb.GetCollection<SomeClass>("ColName");

var data = liteCollection.FindAll().ToList();

//prepare list if id's and delete
var ids = data .Select(l => l.Id).ToList();
var count = liteCollection.DeleteMany(rp => ids.Contains(rp.Id));

Everything looks great, but the database file size keeps growing and is not reducing at all. How to shrink the database?

I get to know some shrink command, but how to use it? A liteDb.Shrink() option I am not seeing and is not available.

  • Is there any API available to shrink the database and how to use it?
  • The above read and delete code I am running in loops which call every 5 minutes, can I use Shrink as well right after delete?
  • Is my predicate right for DeleteMany or is there another way to do this as well?
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user584018
  • 10,186
  • 15
  • 74
  • 160
  • 3
    The method you are looking for is called `Rebuild`. See https://github.com/mbdavid/LiteDB/blob/master/LiteDB.Tests/Engine/Rebuild_Tests.cs – muratgu Apr 17 '20 at 03:19

0 Answers0