3

I am trying to connect to nedb from electron app. CRUD operations work great. BUT I don't see db file (D:/my.db, checked for hidden files). File exists somewhere, because it keeps data even after machine reboot. I suspect that electron threats my path as relative, but I can find it anywhere.

var Datastore = require('nedb'), db = new Datastore({filename : 'D:/my.db', autoload: true});
var doc = { hello: 'world'
           , n: 5
           , today: new Date()
           , nedbIsAwesome: true
           , notthere: null
           , notToBeSaved: undefined  // Will not be saved
           , fruits: [ 'apple', 'orange', 'pear' ]
           , infos: { name: 'nedb' }
           };

db.insert(doc, function (err, newDoc) {   // Callback is optional
   // newDoc is the newly inserted document, including its _id
   // newDoc has no key called notToBeSaved since its value was undefined
});
Uriil
  • 11,948
  • 11
  • 47
  • 68

2 Answers2

4

I found a way to work around this. When creating the datastore in the main.js and making it global, nedb won't use the indexedDB but a local file as specified.

Then in the renderer process get the datastore via Electron.Remote

dorian
  • 51
  • 4
2

The doc says

If you specify a filename, the database will be persistent, and automatically select the best storage method available (IndexedDB, WebSQL or localStorage) depending on the browser.

un.spike
  • 4,857
  • 2
  • 18
  • 38