在下面的代码中使用var更新来计算更新,但是改为零
var updated = 0;
Hosts.find({"model": "cp11"}, {"address":1, _id:0}, function (err, targets) {
if (err) return console.error(err);
console.log("Pinged: " + targets.length);
targets.forEach(function (host) {
ping.promise.probe(host.address, {
timeout: 1
//extra: ["-i 5"]
}).then(function (res) {
if (res.alive) {
Hosts.update({"address": res.host},{"$set": output},{upsert: true}, function(err){
if (err) console.log(err);
});
++updated;
}
});
});
process.exit(updated);
});
一切都很好,除了计数,见下面的结果。
Pinged: 157
Process finished with exit code 0