【发布时间】:2020-02-26 18:58:03
【问题描述】:
现在,考虑一下我有大约一百万用户的 userId(这可能是一个集合)
1234567
1223452
1223454
1223456
1223425
1225451
......
......
......
现在,每个集合都包含文档,看起来像这样
1234567
--- userauth
------ email: any123@gmail.com
1223452
--- userauth
------ email: varun123@gmail.com
......
......
......
现在,如果我想查找具有特定电子邮件 id 的人的 userId(例如:any123@gmail.com),我该怎么做?
对于这个问题,我在云函数内部进行操作。
会比 SQL 更高效吗?
更新:回答我做了这样的事情
class docStore() {
constructor (firestore) {
this.store = firestore
}
async query(collection, condition) {
let colRef = this.store.collection(collection)
if (_.isArray(condition)) {
condition.forEach(predicate => {
colRef = colRef.where(predicate.name, predicate.op, predicate.value)
})
}
const results = []
const snapshot = await colRef.get()
snapshot.forEach(doc => {
results.push({data: doc.data(), id:doc.id})
})
console.notice(results)
return results
}
}
this.store 是admin.firestore()
我的查询是这样的
const checkIfEmailExsist = await docStore.query(SIGNUP_TABLES.userAuth, ['email', '==', userEmail])
这里docStore 高于类,我在其中引用查询
这给了我以下错误
[2019-11-01T13:52:36.873Z](节点:94753) UnhandledPromiseRejectionWarning:错误:参数值 “fieldPath”不是有效的字段路径。路径不能省略。
知道我做错了什么吗?
【问题讨论】:
-
您查看过how to make queries in Cloud Firestore 吗?另外,您是在云功能中还是在网络上?
-
我正在使用 firebase 功能,感谢您查看您分享的链接。
-
@Kolban 更新了问题。我知道电子邮件地址,但不知道 userId
标签: javascript node.js firebase google-cloud-platform google-cloud-firestore