我正在尝试将Excel文件上传到MongoDB数据库。
我使用NPM包管理器将Excel数据转换为MongoDB
mongoXlsx.xlsx2MongoData(path, model, function(err, data){
console.log(data); // (This variable data has an array of objects, each object is a row in Excel.)
});
答案 0 :(得分:0)
您可以使用for循环遍历数组,并将数组的每个元素插入单个mongoDB文档中:
deploy:
- env: mitul-trial (Will change)
org: test (Will change)
host: https://**.com (will remain same)
loc: saas (will remain same)
manifest: manifest_dev.yml (will remain same)
approval: true (will remain same)
- env: mitul1 (Will change)
org: testsomething (Will change)
host: https://**.com (will remain same)
loc: saas (will remain same)
manifest: manifest_dev.yml (will remain same)
approval: true (will remain same)
但在此之前,正如@zenwraight指出的那样,您应该将数据转换为正确的json格式,例如for ( var counter=0 ;counter<data.length;counter++)
{
dataBaseName.colletionName.insertOne(data[counter]);
}
应该变为Name : 'ABC'
(其他字段也是如此)