Test Test
Test Test

Reputation: 165

NEDB is clearing content of file when app's relauched

I have written NodeWebKitApp in which I save user's data (like name, uid and settings) for later use. I can insert a document fine and I can see its content. The file size is about 2KB.

But, if I close the app and then re-open it, the saved data is lost and I see a file size of 0 bytes.

Debugging, I discovered that this behavior occurs when the following line is executed:

db = new Datastore({ filename: myPath, autoload: true });

I tried to debug nedb/persistance.js but could not resolve the issue. I also tried loading the database manually by calling loadDatabase(function(err) {}) but without success.

Here is a snippet of code:

var Datastore = require('nedb'),  
..
..
..                                                               
myPath = "<User-Home>/.myApp/user.db",
db = new Datastore({ filename: myPath, autoload: true });

Upvotes: 1

Views: 1590

Answers (2)

ivandov
ivandov

Reputation: 653

Just in case you didn't insert the data into the .db file with an actual insert() command, make sure your entries have a _id field for each JSON row.

Upvotes: 1

Michael Blankenship
Michael Blankenship

Reputation: 1669

Are you sure that "/.myApp/user.db" is a valid path? You might try "./myApp/user.db" instead.

Upvotes: 0

Related Questions