LokiDB
LokiDB copied to clipboard
Update record followed by delete record without save leaves data behind
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
update a record delete that record save database values left in database
Expected behavior
no values left in database
Minimal reproduction of the problem with instructions
save after (update record and delete record) leaves behind values in DB save after update, save after delete record does not leave behind values
What is the motivation / use case for changing the behavior?
Explicitly saving database after an update and delete would leave behind records
Environment
LokiDB version: 2.0.0-beta.8
Browser/Node version: Chrome 71
Sorry for the really late reply. I tried to reproduce the bug, but it didn't work:
const db = new Loki("myTestApp3");
db.initializePersistence()
.then(() => {
const coll = db.addCollection<Name>("myColl");
// Insert documents.
coll.insert({name: "Hello"});
coll.insert({name: "World"});
return db.saveDatabase(); // save or not save, doesn't changes anything
}).then(() => {
// Update and remove one record.
const coll = db.getCollection<Name>("myColl");
const doc = coll.find()[0];
expect(doc.name == "Hello")
doc.name = "Good by";
coll.update(doc);
coll.remove(doc);
return db.saveDatabase();
})
.then(() => {
const all = db.getCollection<Name>("myColl").find();
expect(all.length).toEqual(1);
expect(all[0].name).toEqual("World");
})
.then(() => {
// Load database.
const db2 = new Loki("myTestApp2");
return db2.initializePersistence({autoload: true})
.then(() => {
// Only one record present.
const all = db.getCollection<Name>("myColl").find();
expect(all.length).toEqual(1);
expect(all[0].name).toEqual("World");
});
})
.catch(e => {
fail(e);
})
.then(() => {
done();
});