techfort / LokiJS

javascript embeddable / in-memory database
http:/techfort.github.io/LokiJS
MIT License
6.73k stars 482 forks source link

Collection.clear() won't clear all pages - LokiPartitioningAdapter + LokiIndexedAdapter #840

Closed condda closed 4 years ago

condda commented 4 years ago

Hi,

When I try to clear a collection which has been partitioned, the "initial" partition is cleared properly, but the rest of the pages (partitions) created by LokiPartitioningAdapter are not.

I still see in the IndexedDB inspector on Chrome that the partition created by LokiPartitioningAdapter still contains data.

The "initial" partition is is cleared properly.

After I clear the collection I see:

{
app: "testDB_idb_adapter"
key: "testDB.0.0"
appkey: "testDB_idb_adapter,testDB.0.0"
val: "$<↵"
id: 2
}

{
app: "testDB_idb_adapter"
key: "testDB.0.1"
appkey: "testDB_idb_adapter,testDB.0.1"
val: "{DATA}"
id: 3
}

This is the Lokijs instance code

var partitioningAdapter = new loki.LokiPartitioningAdapter(
    new LokiIndexedAdapter('testDB_idb_adapter'),
    {
        paging: true,
        pageSize: 25*1024*1024
    }
);
_db = new loki('testDB', {
    adapter: partitioningAdapter,
    autoload: true,
    autoloadCallback: function() {
    _db.loadDatabase({}, function() {
        if (!_db.getCollection(collection)) {
            _db.addCollection(collection, {
                unique: ['id'],
                indices: ['id'],
                disableMeta: true
            });
        }
    });
});

I tried different ways of clearing the collection:

var collection = _db.getCollection(collectionName);
collection.clear();
//collection.removeWhere(function(){ return true;});
//collection.chain().remove();
_db.saveDatabase()

Is it something i'm missing when using LokiPartitioningAdapter?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.