是否可以在数据库NeDB中插入整个.json文件?

时间:2017-04-19 12:17:46

标签: json nedb

我想知道是否可以在NeDB数据库中插入整个json文件。 我正在尝试将.xlsx文件转换为.json文件,我成功但我想知道是否可以在NeDB数据库中插入整个.json文件

2 个答案:

答案 0 :(得分:0)

NeDB的github文档中引用它。

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

可以通过加载JSON文件替换变量doc。您可以使用jQuery和getJSON加载JSON文件。

答案 1 :(得分:0)

最后,我没有使用jQuery,这是我的解决方案

fs = require('fs');
var test = JSON.parse(fs.readFileSync('filename.json', 'utf8'));