LokiDB icon indicating copy to clipboard operation
LokiDB copied to clipboard

collection.removeCollection does not get autosaved into persisted DB

Open cepm-nate opened this issue 5 years ago • 1 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/LokiJS-Forge/LokiDB/blob/master/CONTRIBUTING.md#question

Current behavior

When you remove a collection, the 'autosave' does not pick up the change.

Expected behavior

I would expect autosave to pick up the change, so that the deletion of the collection is properly persisted.

Minimal reproduction of the problem with instructions


const idbAdapter = new IndexedStorage(dbName);
const db = new Loki('dbfile');
let persistenceOptions = {
	adapter: idbAdapter,
	autosave: truep,
	autosaveInterval: 900, // 900ms.
	autoload: true,
	throttledSaves: false,
};
wdb.initializePersistence(persistenceOptions)
.then((r) => {
	console.log('Done loading.');
	const collection = db.addCollection(`Test_500`);
	collection.insert({ foo:'bar' });
	setTimeout(() => {
		// So autosave has run
		db.removeCollection('Test_500');
		setTimeout(() => {
			// so autosave has had time to do it's thing again
			console.log('Collections in db:', db._collections.length);
			console.log('Collections last persisted', db._persistenceAdapter._dbref._collections.length);
			console.log('Check DevTools  Application storage. The DB should be EMPTY.');
		}, 2000);
	},2000);
})

What is the motivation / use case for changing the behavior?

In my mind, deletion of data should "stick", and not show up again if the browser is refreshed. In my project I can work around it by 'clearing' a collection instead of deleting and re-creating it, but this does feel like a bug that should be tracked.

Environment


LokiDB version: 2.1.0
Browser/Node version: Browser X.Y.Z.

cepm-nate avatar Sep 27 '20 21:09 cepm-nate

Confirming this issue as well. I have similar setup using adaptor.

greaterking avatar Jan 08 '21 23:01 greaterking