我有两个Json文件。我需要在mongodb中合并它们。
{"indicate_public": "public",
"indicate_compulsory": "man",
"profile_photo": "Foto"}
这是我的第二个档案:
{"indicate_public": "public",
"indicate_compulsory": "verplicht",
"test_tooltip": "tooltip"}
每行应在名为:languages
的新集合中插入seprate行答案 0 :(得分:0)
似乎robomongo或Mongochef中没有用于导入此类数据的工具。所以我将这些代码写入server / methods / publicationMethods.js
中的js文件中 readLanguageFile() {
var fs = require('fs');
var frfileName = process.env.PWD +'/both/I18N/fr/fr.i18n.json';
var nlfileName = process.env.PWD +'/both/I18N/nl/nl.i18n.json';
var frcontent = fs.readFileSync(frfileName, 'utf8')
var nlcontent = fs.readFileSync(nlfileName, 'utf8')
var frresult = JSON.parse(frcontent);
var nlresult = JSON.parse(nlcontent);
for (var key in frresult) {
var param = key
var frVal = frresult[key];
var nlVal = nlresult[key];
console.log('herein read json');
if (frVal ==null)
{
frVal==""
}
if (nlVal ==null)
{
nlVal==""
}
var object = {}
object.key=param
object.frVal =frVal
object.nlVal=nlVal
//console.log('object',object);
Languages.insert(object)
}
},