-1

I was wondering if it was possible to insert a whole json file in a NeDB database . I'm trying to turn an .xlsx file to a .json file, I succeed but I'm wondering if it's possible to insert the whole .json file in a NeDB database

Tewan
  • 171
  • 1
  • 12
  • If you `base64` the XLSX file, you can insert it as a string. So it's possible, sure. –  Apr 19 '17 at 12:21

2 Answers2

0

Reference this from the github documention for NeDB.

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
});

Where the variable doc can be replaced by loading your JSON file. You can the load the JSON file by using jQuery and getJSON.

uzr
  • 1,210
  • 1
  • 13
  • 26
  • When I tried your solution I had an error : `Cannot read property 'getJSON' of undefined` – Tewan Apr 19 '17 at 13:20
0

Finally, I didn't use jQuery, here is my solution

fs = require('fs');
var test = JSON.parse(fs.readFileSync('filename.json', 'utf8'));
Tewan
  • 171
  • 1
  • 12