0
목록을 검사하는 코드를 작성하고 목록의 각 항목이 다른 목록에 있는지 확인합니다. 항목을 찾지 못하면 데이터베이스에 추가됩니다.코드가 전체 스크립트를 실행하지 않습니다.
검색 코드가 올바르지 만 (db.scan이라고 말한 부분) 코드가 실행되지 않아 코드가 통과하지 못하는 부분이 있습니다 (console.log 부분을 실행하지 않기 때문에 "데이터베이스에 저널 입력 ..."). . "기사의 제목"나는이 코드를 실행하면 는 아무 일도 발생하지 않습니다. 적어도 오류가 없습니다 ...하지만 그것조차 CONSOLE.LOG 부품을 기록하지 않으면 뭔가 잘못 그래서.
// accessing the database
function DatabaseTime(sourcesDates, timeAdded, links, titles, descriptions) {
sourcesDates = sourcesDates;
links = links;
titles = titles; // this will be used to check on our articles
descriptions = descriptions;
var autoParams;
var databaseOperation = function (sourcesDates, timeAdded, links, titles, descriptions) {
var scanParams = { TableName: "Rnews" }
// using code to setup for accessing the 2nd list
db.scan(scanParams, function(err, scanData) { // scanData = the 2nd list we are going to work with
var counter = 0; // just a way to help make my code more accurate as seen later in the loops
var counter2 = 0;
// this is the first list iterating on
for (var i = 0; i < links.length; i++) {
counter = 0;
// looping through items in second list
for (var x = 0; x < scanData.Items.length; x++) {
// if article is not in db
if (titles[i] !== scanData.Items[x].title) {
continue;
}
else if (titles[i] === scanData.Items[x].title) {
// intention is to immediately move to the next item in the first list if this block executes
console.log("Article found: \"" + titles[i] + "\". Not proceeding anymore with article.");
counter++;
break;
} else {
// if this article isnt found anywhere in the list we are checking on, add to database
if (x === scanData.Items.length && counter !== 0) {
autoParams = {
TableName: "Rnews",
Item: {
title: titles[i],
source: sourcesDates[i],
url: links[i],
description: descriptions[i],
lastAddOrUpdated: dbTimeStamp,
timePublish: timeAdded[i]
}
}
console.log("Entering journal to database: " + titles[i]);
db.put(autoParams, function(err, data) {
if(err) throw err;
});
//}
}
}
}
}
});
//console.log("Complete");
};
databaseOperation(sourcesDates, timeAdded, links, titles, descriptions);
}
//// END
디버거를 사용하여 코드를 단계별로 실행하고 오류가 발생한 위치를 확인하십시오. (['node-inspector'] (https://www.npmjs.com/package/node-inspector)는 NodeJS 용 디버거 중 하나입니다. –
시도해 보겠습니다. – Chris
Pro 팁 : 코드가 켜져 있습니다. 얼마나 굉장한 지에 대한 그래프가 아닙니다. 빠른 속도로이 코드를 생각하는 것은 불가능합니다. –