【发布时间】:2020-03-12 19:33:47
【问题描述】:
我有以下内容来更新我的 Firestore 文档。但是有一个错误说必须正确处理promise。我已经在我的函数中添加了 try catch..谁能告诉我还有什么遗漏的?
export const updateCustomer = functions.https.onRequest(async (req, resp) => {
try
{
await db.collection('Users').where('CompanyId', '==', req.body.CompanyId)
.where('CustomerId', '==', req.body.CustomerId)
.get()
.then(snapshot => {
snapshot.forEach(doc =>
{
db.collection('Users').doc(doc.id).update(
{
CustomerName : req.body.CustomerName,
MobileNo : req.body.MobileNo,
DOB: req.body.DateOfBirth,
Email : req.body.Email,
PreferredLanguage: req.body.PreferredLanguage
}
)
})
})
.catch(error => resp.status(500).send(error));
resp.status(200).send(req.body);
}
catch(error)
{
console.error(error);
resp.status(500).send({ Message: error, StatusCode: '500', Status: 'Error'});
}
})
【问题讨论】:
标签: typescript promise google-cloud-firestore