Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletions come back when insert new item #148

Open
GreyCode3 opened this issue Apr 1, 2024 · 0 comments
Open

Deletions come back when insert new item #148

GreyCode3 opened this issue Apr 1, 2024 · 0 comments

Comments

@GreyCode3
Copy link

I am writing some CLI functions and find a new situation to cause deletions back with release 4.4.1. Quite similar to #127. So, I still use example in #127:

use polodb_core::{Database, Document, bson::doc};

let db = Database::open_file("tasks.db").unwrap();
let col = db.collection::<Document>("tasks");

col.find(None)?; // The document [{ "name": "1" }, { "name": "2" },{ "name": "3" }] is returned

After that function dead. Then I read db again and delete one item:

use polodb_core::{Database, Document, bson::doc};

let db = Database::open_file("tasks.db").unwrap();
let col = db.collection::<Document>("tasks");

col.delete_one(doc! {"name": "3"})?;
col.find(None)?; // The document [{ "name": "1" }, { "name": "2" }] is returned

Now insert new data:

use polodb_core::{Database, Document, bson::doc};

let db = Database::open_file("tasks.db").unwrap();
let col = db.collection::<Document>("tasks");

col.insert_one(doc! {"name": "4"})?;
col.find(None)?; // The document [{ "name": "1" }, { "name": "2" },{ "name": "4" }] is returned

So far so good. But problem occurs if I read again with new process (means I execute function again):

use polodb_core::{Database, Document, bson::doc};

let db = Database::open_file("tasks.db").unwrap();
let col = db.collection::<Document>("tasks");

col.find(None)?; // The document [{ "name": "1" }, { "name": "2" },{ "name": "3" }] is returned !!!!

I just guess that the wal file never flush to disk. So when a new process execute and read from disk, db still use old file without updating... Maybe that's why delete and read db in same process, everything seems okay.
If I insert same data again:

use polodb_core::{Database, Document, bson::doc};

let db = Database::open_file("tasks.db").unwrap();
let col = db.collection::<Document>("tasks");

col.insert_one(doc! {"name": "4"})?;
col.find(None)?; // The document [{ "name": "1" }, { "name": "2" },{ "name": "3" },{ "name": "3" },{ "name": "4" }] is returned !!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant