从 DocumentReference flutter 获取数据
Get data from DocumentReference flutter
我正在尝试使用 Cloud Store 触发器功能更新文档。下面是代码,但是当我尝试部署该函数时出现此错误:
119:30 错误解析错误:意外的令牌 deviceDoc
✖ 1 个问题(1 个错误,0 个警告)
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate((change, context) => {
const afterData = change.after.data();
const agentId = afterData.agentId;
console.log('agentId: ', afterData.agentId);
console.log('A transaction has been updated');
/**** GET DEVICE INFORMATION ****/
const deviceDoc = db.collection('device').doc(agentId);
console.log('deviceDoc: ', deviceDoc);
if (deviceDoc == null) {
console.log('No device document found');
}
const deviceData = await deviceDoc.get(); <<<< THIS IS THE PROBLEM CODE
});
最后一行是导致错误的那一行,但我不知道为什么。我在另一个函数中使用了同一行,它在那里工作。
请帮忙!
谢谢
您需要将 async
添加到您的回调中,如下所示:
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate(async (change, context) => {
//... rest of the code
});
我正在尝试使用 Cloud Store 触发器功能更新文档。下面是代码,但是当我尝试部署该函数时出现此错误: 119:30 错误解析错误:意外的令牌 deviceDoc ✖ 1 个问题(1 个错误,0 个警告)
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate((change, context) => {
const afterData = change.after.data();
const agentId = afterData.agentId;
console.log('agentId: ', afterData.agentId);
console.log('A transaction has been updated');
/**** GET DEVICE INFORMATION ****/
const deviceDoc = db.collection('device').doc(agentId);
console.log('deviceDoc: ', deviceDoc);
if (deviceDoc == null) {
console.log('No device document found');
}
const deviceData = await deviceDoc.get(); <<<< THIS IS THE PROBLEM CODE
});
最后一行是导致错误的那一行,但我不知道为什么。我在另一个函数中使用了同一行,它在那里工作。
请帮忙! 谢谢
您需要将 async
添加到您的回调中,如下所示:
exports.onTrxnUpdate = functions.firestore.document('/trxns/{trxnId}').onUpdate(async (change, context) => {
//... rest of the code
});