【发布时间】:2019-03-06 06:39:46
【问题描述】:
我在使用 dynamoDB 时遇到问题,它没有在 for 循环中给我查询结果。查询确实执行了,但它只在循环完成后执行:
readMatchData(JSON) {
return new Promise((resolve, reject) => {
for (var jsonInfo of JSON.Feed.MatchData) {
var matchID = jsonInfo['@attributes'].matchID;
console.log("matchID: " + matchID);
var homeTeamID = team['@attributes'].homeTeamID;
var params = {
TableName: "Teams",
KeyConditionExpression: "#teamID = :teamID",
ExpressionAttributeNames: {
"#teamID": "teamID"
},
ExpressionAttributeValues: {
":teamID": homeTeamID
},
ReturnConsumedCapacity: "TOTAL"
}
docClient.query(params, function(err, data) {
if (err) {
//console.log("We have an error when looking for the team in the Teams table");
console.log(err);
} else {
if (data.Count === 0) {
//We did not find this ID in the db so we can add it.
console.log("The team doesn't exist");
} else {
data.Items.forEach(function(item) {
console.log("Team " + item.teamID + " " + item.teamName + " found in the database");
})
}
}
});
}
resolve("done");
});
}
在控制台中返回我:
匹配ID:3434
匹配 ID:3543
在数据库中找到3388 Hill U23 Team
在数据库中找到 Team 44108 Bridge U23
而不是:
匹配ID:3434
在数据库中找到3388 Hill U23 Team
匹配 ID:3543
在数据库中找到 Team 44108 Bridge U23
【问题讨论】:
标签: node.js amazon-web-services aws-lambda amazon-dynamodb