我是 JS 的新手,我被困在这一点上。我试图在开始新查询之前清除我的数据库,并且它一直停留在 collection.find 命令上。如果我删除了清除数据库的代码,一切正常。
router.get('/parse', function(req, res) {
collection.remove({})
collectionweb.remove({})
collectionhit.remove({})
//Converter Class
var Converter = require("csvtojson").core.Converter;
var fs = require("fs");
var csvFileName = "./download/company.csv";
var fileStream = fs.createReadStream(csvFileName);
//new converter instance
var param = {};
var csvConverter = new Converter(param);
request({
uri: "http://online.barrons.com/news/articles/SB50001424053111904537004580085820431503044?mod=BOL_twm_fs",
}, function(error, response, body) {
collectionweb.insert({
"website": body
});
});
//end_parsed will be emitted once parsing finished
csvConverter.on("end_parsed", function(jsonObj) {
//Insert into DB
collection.insert(jsonObj);
});
fileStream.pipe(csvConverter);
collectionweb.find({}, function(e, docs1) {
for (var j in docs1) {
var body = docs1[j]
var webs = body.website
console.log(1)
collection.find({}, function(e, docs) {
for (var i in docs) {
console.log(2)
var companies = docs[i]
var Score = 0;
$words = webs.search(companies.Symbol);
console.log(3)
if ($words > 0) {
StockScore++console.log(Score)
collectionhit.insert(companies)
collectionhit.update({
"Name": companies.Name
}, {
'$set': {
"score": Score
}
})
} else {};
};
});
};
});
});