现在一直在努力导入CSV,使用meteor-file从客户端上传并使用node-csv服务器端转换为CSV .我基本上需要使用用户上传的CSV文件中的数据填充我的集合.
/server/filehandler.js:
Meteor.methods({
'uploadFile': function (file) {
if(file.start === 0) {
console.log(file.name);
console.log(file.type);
console.log(file.size);
}
file.save('/home/russell/tmp',{});
var buffer = new Buffer(file.data);
CSV().from(
buffer.toString(),
{comment: '#', delimiter: ',', quote: ''}
)
.to.array( function(data){
//console.log(data);
for(var row=0; row<data.length; row++) {
console.log(data[row]);
newRecord = {
'firstname': data[row][0],
'lastname': data[row][1],
'email': data[row][2],
'emailshort': data[row][3],
'emailmain': data[row][4],
'domain': data[row][5]
};
console.log(newRecord);
reas.insert(newRecord); // *** _dynamic_meteor ERROR here!
}
} );
} // uploadFile
});
Run Code Online (Sandbox Code Playgroud)
console.log告诉我CSV到阵列的转换很好.
集合reas在/lib/models.js中设置为集合 - /lib与/ …
我只是在调查OPA,试图从传统的LAMP背景中实现跨越,所以这是我的第一个新手问题:
我可以拥有两个共享相同数据库的OPA应用程序,比如一个写入数据库而另一个从中读取数据库?