[英]My firestore sucurity rule for getting multiple documents doesn't work
我有这个规则
allow read: if request.auth.uid == resource.data.author
而且它不允许我使用 getDocs 获取多个文档。
但它允许使用 getDoc 获取文档。
PS:我用它来检索文件
const col = collection(db, collectionPath)
const documents = await getDocs(col)
并得到这个错误
FirebaseError:权限缺失或不足。
但这有效
const col = collection(db, collectionPath)
const document = await getDoc(doc(col,documentID))
您将security rules 与 filters 混淆了。 您问题中的安全规则只会让所有文档都满足该规则的查询通过,因此如果您尝试使用getDocs(collection)
获取整个集合,它不会返回任何内容。
相反,尝试使用 Author 字段查询数据库,就像这个答案中的方法一样,它使用whereEqualTo()
按字段过滤结果:
const col = firestore.collection(db, collectionPath).whereEqualTo("author", author)
const documents = await getDocs(col)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.