typicode / lowdb

Simple and fast JSON database
MIT License
21.35k stars 918 forks source link

db.read() not working properly? #531

Closed Gustiviy closed 1 year ago

Gustiviy commented 2 years ago

From my understanding read() is supposed to read the file, and put it into db, but using console.log shows the old values.

{ "users": [ { "tag": "user#1111", "point": 4 }] }

This is the JSON file (it has multiple entries but that's not the point)

db.data.users[i].point += 1; db.write(); db.read(); (i is from the for loop filter)

This does change the JSON file, however db still has the old number. ({ tag: 'user#1111', point: 3 })

stefnotch commented 2 years ago

Could you post a bit more code?

For example, if you're creating the database with the async stuff, then it's possible that the writing happens later. With the async stuff, the correct code would involve await db.write();

typicode commented 1 year ago

Closing as the issue is old, and issue may have been solved since then. Feel free to reopen if needed :+1: