でオブジェクトが未定義と呼ばれていますが、オブジェクトtが正常に印刷された状態で「最初」が印刷されますが、そのコールバック後にコールバックが入力されます。 applied(t)関数では、エラー-TypeError:未定義のプロパティ '_id'を読み取ることができません。なぜなら、オブジェクトtは何らかの理由で未定義であるからです。このコールバック関数に入る前に未定義でなかった場合、何が原因である可能性がありますか? update()はMongoDB関数です。内部ネストされたコールバック関数
function applied(t)
{
this.transactions.update(
{
_id: t._id, state: "pending" },
{
$set: { state: "applied" },
$currentDate: { lastModified: true }
}
)
}
function applytransaction(t,f,fb)
{
x=fb(t.value);
y=f(t.value);
this.model.update(
{ _id: t.source, pendingTransactions: { $ne: t._id } },
{ $inc: { bal:x }, $push: { pendingTransactions: t._id } }
, function(err,t,y) {
console.log("First "+t);
this.model.update(
{ _id: t.destination, pendingTransactions: { $ne: t._id } },
{ $inc: { bal: y }, $push: { pendingTransactions: t._id } }
, function(err, t) {
console.log("Second " +t);
applied(t);
});
});
}
「t」という名前の変数が多すぎます。それらに一意の名前を付けます。そのためには、1文字と2文字の変数名の使用をやめ、すべての変数に意味のある名前を付けてください。 – JLRishe
2回目の更新が失敗するので、明らかに 't'はそれが – adeneo