【发布时间】:2019-05-21 10:57:38
【问题描述】:
我有一个包含 2 个字段的文档:field1,field2(为简单起见更改了名称。
从云函数中,我试图从 field1 中获取值。这些函数不是该特定文档的触发器,我得到的值如下:
const user_collection = db.collection("user")
const photoName = user_collection.doc(userid).field1
但是,我在undefined 中得到的回报。我尝试使用 data() 或 get() 方法,但最终出现错误...is not a function。在文档或 SO 中找不到任何帮助我从文档中获取字段值的内容。
关于如何提取该字段的任何建议?
编辑:
exports.onUserDeletion = functions.auth.user().onDelete((user) => {
const userid = user.uid
const photoName = user_collection.doc(userid).photo //<--- this is "undefined"
const filePath = `user_photo/${photoName}`
const file = bucket.file(filePath)
console.log(`userid: ${userid} photoName: ${photoName} filePath: ${filePath} file: ${file}`)
return highscore_collection.doc(userid).delete().then(user => {
return user_collection.doc(userid).delete().then(user => {
return file.delete()
})
})
})
【问题讨论】:
-
添加你的云功能和你的数据库截图
-
阅读文档应该会有所帮助:cloud.google.com/firestore/docs/query-data/…
-
@PeterHaddad 我编辑了我的问题以添加这些。
-
你怎么知道它的未定义?控制台日志?
-
@SomeshMukherjee 是的,完全正确。我也用 console.log() 部分在我的整个函数中编辑了我的问题。
标签: javascript firebase google-cloud-firestore google-cloud-functions