例如,我制定了以下规则(有一个名为电子邮件的字段)
service cloud.firestore {
match /databases/{database}/documents {
match /collection/{documentId} {
allow read: if request.auth.token.email in resource.data.email;
//resource.data.email here is an Array!!!
}
}
}
但是如何通过where
查询获取任何数据,我的意思是这样:
db.collection("store").where("id", "==", "1").onSnapshot(function (querySnapshot) {
querySnapshot.forEach(doc => {
console.log("realtime---->", doc.data().cities);
})
})
权限问题仍然存在...... documentation表明我应该在email
字段中包含与上面定义的规则相同的约束。如何在Array
中处理它?</ p>
答案 0 :(得分:0)
好吧,我终于发现,由于官方文档,查询数组是不可能:https://firebase.google.com/docs/firestore/solutions/arrays已经说过了。
你可以做的是将{
hash1:1,
hash2:0
}
作为一个对象,比如
//here I set the hash as user uid, and query through carId
allow read,write:if get(/databases/$(database)/documents/car/$(resource.data.carId)).data.authfield[request.auth.uid]=="1"
键值对可以表示具有不同权限级别的不同用户。 制定如下规则:
db.collection("col1").where("carId","==","ABC").where("authfield.hash1","==","1")
然后,通过
查询hash1
顺便说一句,where
字段不能设置为电子邮件格式或其他格式点,因为它只识别第一个 dot 作为对象及其属性之间的分隔符号。
例如,对于名为“dou@company.com”的字段,如果将其放在{{1}}查询中,它会将其视为对象“dou @ company”,并读取其属性“ COM”。