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
專業提示:代碼打開它的一面是而不是它是多麼棒的圖表。以快速的方式思考這段代碼是不可能的。 –