liulqiuyu
2020-01-16 16:47:49 +08:00
-----代码如下-------
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)
}
});
}