【发布时间】:2020-02-12 22:16:14
【问题描述】:
我正在寻找最好的方法:
1. 查询一个结果,或者
2.从查询中提取第一个结果
试过了:collection[0] 和 collection.pop() 或 collection.shift() 没有任何效果
我真的不喜欢我正在使用的代码,但它可以工作......
export const findUserByEmail = email => {
return firestore()
.collection('users')
.where('email', '==', email.toLowerCase())
.get()
.then(collection => {
console.log(collection)
let user
collection.forEach(doc => user = doc.data())
return user
})
}
【问题讨论】:
-
您的文字显示为
result,但您的代码显示为collection。这只是一个错字吗? -
谢谢,是的,这是一个错字。立即编辑
标签: javascript firebase google-cloud-firestore