0
是MonogoDB n Nodejs的新用戶。建立一個簡單的產品目錄。嘗試將CSV文件內容導入到mongodb。我得到了語法錯誤::意外的標識符錯誤:有什麼辦法可以解決這個問題嗎? 我很想知道如何使用Git上的ya-csv包。誰能幫忙?如何在GitHub上使用適用於MongoDB的軟件包?
是MonogoDB n Nodejs的新用戶。建立一個簡單的產品目錄。嘗試將CSV文件內容導入到mongodb。我得到了語法錯誤::意外的標識符錯誤:有什麼辦法可以解決這個問題嗎? 我很想知道如何使用Git上的ya-csv包。誰能幫忙?如何在GitHub上使用適用於MongoDB的軟件包?
嘗試如下:
npm install ya-csv //install package
//Put this code in your .js file
var csv = require("ya-csv");
var validRows = [];
var reader = csv.createCsvFileReader("/csv/file.csv", {columnsFromHeader:true,'separator': ',' , encoding: "utf8"});
reader.addListener('data', function(data) { //if rows are in correct format then it will push into array
if(data){
validRows.push(data);
}
});
reader.addListener('end', function(){ //this method will be called after reading all csv rows
validRows.forEach(function(data){
//console.log(data.name); //get your data like this
});
});
reader.addListener('error', function(err){
console.log(err); //if any error occurred
});
如需更多詳細信息請點擊此鏈接
你拉從GitHub源,直接到你的項目?或者你是否通過npm安裝? 'npm install ya-csv' –
你是如何使用這個軟件包的?請將相關來源添加到您的問題中。它可能是導致該錯誤的任何事情。 – WiredPrairie
對不起,我想試試ya-csv。但一般進口聲明奏效。 @WiredPrairie – user3658946