【发布时间】:2021-04-20 19:21:13
【问题描述】:
我正在尝试获取公共集合中的特定文档,但我收到错误“缺少权限或权限不足”。
但是,我觉得我写得很好:
match /posts/{userId}/userPosts/{postId} {
allow read: if isSignedIn() && request.query.limit <= 10;
allow write, update, delete: if false;
match /likes/{document=**} {
allow read: if isSignedIn();
allow write: if false;
}
match /comments/{document=**} {
allow read: if isSignedIn();
allow write: if false;
}
}
使用此代码,安全规则可以正常工作:
const query = firestore
.collection("posts")
.doc(userId)
.collection("userPosts")
.orderBy("date", "desc")
.startAfter(startAfter);
const querySnapshot = await query.limit(limit).get();
但是...有了这个,我得到了错误:
const myPostRef = firestore
.collection("posts")
.doc(userId)
.collection("userPosts")
.doc(postId);
const myPostDoc = await myPostRef.get();
为什么我无法获得特定的文档?
【问题讨论】:
-
当你执行一个简单的
.get()时你确定request.query.limit有一个值吗? -
删除这是问题所在!但是……我需要它。有什么方法可以结合这两个规则?
-
可能是 OR - 类似于“已登录 AND(非查询 OR 限制
-
你确定发送正确的
postId?
标签: javascript firebase google-cloud-firestore