【发布时间】:2019-09-17 02:28:58
【问题描述】:
使用 Firebase Cloud Functions 我正在尝试扩展 Firestore 文档中的 uri,并将其替换为扩展的 uri。
我正在使用运行良好的 tall npm 包 (https://www.npmjs.com/package/tall),但我无法将生成的扩展 uri 放入我的对象中以放回 firestore。
我相信它不会在我的其余函数完成之前返回,因此不会给我数据。当我尝试使用页面上的示例进行异步并使用 await firebase 时出现错误。
我假设我错过了一些非常简单的东西,但是在上传到云功能、测试和重试一天之后,我感到非常沮丧。
我错过了什么?
exports.addonSanitized = functions.firestore
.document('addons/{addonId}')
.onCreate(doc => {
const addonId = doc.id;
const addon = doc.data();
const expandedLink = tall(addon.link)
.then(unshortenedUrl => console.log('Tall url', unshortenedUrl))
.catch(err => console.error('AAAW ????', err));
const sanitized = {
summary: `${expandedLink}`
};
return admin
.firestore()
.collection('addons')
.doc(addonId)
.update(sanitized)
.then(doc => console.log('Entry Sanitized', doc));
});
我希望扩展链接返回扩展链接。文档中输入的是[object Promise]
【问题讨论】:
标签: javascript firebase async-await google-cloud-firestore google-cloud-functions