踩空一下午

cdm终端开启:
C:\WINDOWS\system32>mongod --dbpath E:\g-dome2\database
导入数据库
PS E:\g-dome2\node-e> mongoimport -d ershouche -c cars cardata.json --drop

踩空一下午_第1张图片
可能是数据没达到0.001G,死坑了

const path=require(‘path’);
const fs=require(‘fs’);
const _=require(‘lodash’);

const carbasedataFilePath=path.resolve(__dirname,"./carbasedata.json");
const writeDataFilePath=path.resolve(__dirname,"./cardata.json");
const carimagePath=path.resolve(__dirname,"./img");

var arr=JSON.parse(fs.readFileSync(carbasedataFilePath).toString());

for(var i=0;i arr[i].price=.random(0 , 1000)/10;
arr[i].name=
.sample([“肖战”,“北堂墨染”,“魏无羡”,“蓝忘机”]);
arr[i].images={
“view” :fs.readdirSync(carimagePath+"/"+arr[i].id+"/view"),
“inner” :fs.readdirSync(carimagePath+"/"+arr[i].id+"/inner"),
“more” :fs.readdirSync(carimagePath+"/"+arr[i].id+"/more"),
“engine”:fs.readdirSync(carimagePath+"/"+arr[i].id+"/engine")
}
}

for(var i=0;i fs.appendFileSync(writeDataFilePath ,JSON.stringify(arr[i])+"\r\n");
}

生成json数据代码 node .init/loash-h.js

你可能感兴趣的:(踩空一下午)