1
liulqiuyu OP -----代码如下-------
function readByfile(value,mongodb){ let readPath=path.resolve(__dirname,'json/json/'+value); let data = fs.readFileSync(readPath,'utf-8'); mongodb.insertMany(JSON.parse(data),function(err){ console.log(err); }); } function readDir(dirpath){ let files = fs.readdirSync(dirpath); _.each(files , function(value){ if(value.startsWith('authors.song')){ readByfile(value,song_author) }else if(value.startsWith('authors.tang')){ readByfile(value,tang_author) }else if(value.startsWith('poet.tang')){ readByfile(value,tang_poet) }else if(value.startsWith('poet.song')){ readByfile(value,song_poet) } }); } |
2
lovemegowin 2020-01-17 09:11:03 +08:00
改成流处理
|