【发布时间】:2019-10-02 13:05:28
【问题描述】:
我正在尝试根据此博客 https://firebase.googleblog.com/2018/08/better-arrays-in-cloud-firestore.html 从数组中获取“读取”规则
var db = firebase.firestore();
db.collection("_users").where("viewers", "array-contains", myUID)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, ' => ', doc.data());
});
});
在 AngularFirestore 中相同
this.itemsCollection_users = this._afDB.collection("_users", ref => ref.where("viewers", "array-contains", myUID)))
The DB
/_users/EGsht477klOKW0YeYsryo0j8AkY2/sometext = "hello",
/_users/EGsht477klOKW0YeYsryo0j8AkY2/viewers [
0: hKeDFsC6wOQZGz0rP7SnJ7Vo5O73,
1: Y8xbH2avmCWmm1EBK7wappM2qE03
]
数据库规则 服务云.firestore {
match /databases/{database}/documents {
match /_users/{userId} {
allow read: if request.auth.uid in resource.viewers;
}
}
}
所以用户 EGsht477klOKW0YeYsryo0j8AkY2 应该可以从“查看器”中列出的任何用户访问(读取)
我得到的警告是……
ERROR FirebaseError: Missing or insufficient permissions.
【问题讨论】:
标签: javascript angular google-cloud-firestore firebase-security