Javascript firestore安全规则资源。数据为空对象
在firestore安全规则中,resource.data始终是一个emtpy对象,这是一个bug还是什么 我的firestore规则:Javascript firestore安全规则资源。数据为空对象,javascript,google-cloud-firestore,firebase-security,Javascript,Google Cloud Firestore,Firebase Security,在firestore安全规则中,resource.data始终是一个emtpy对象,这是一个bug还是什么 我的firestore规则: service cloud.firestore { match /databases/{database}/documents { match /hospitals/{document=**}{ // allow read :if resource.data.size() == 0; //this return true, resou
service cloud.firestore {
match /databases/{database}/documents {
match /hospitals/{document=**}{
// allow read :if resource.data.size() == 0; //this return true, resource.data is an empty object
allow read :if resource.data.name != null; // this doesn't work
}
}
}
我的javascript:
auth().onAuthStateChanged((user) => {
if (user) {
//db is the firestore instance
db.collection('/hospitals').get()
.then(printResult)
} else {
}
})
这是我当前的数据库快照
解决了的:
谢谢弗兰克的回答
在我的例子中,问题在于当我们查询多个文档时,firestore安全性不会评估实际的文档值
//this doesn't firestore doesnt' evaluate the documetn
db.collection('hospitals').get()
//this will work ,if you need to compare the actual value
db.document('hospitals/somehospital').get()
安全规则本身不过滤数据。它们只是对客户端可以读取的数据实施规则。您的客户目前正在尝试读取所有医院的信息。由于您的安全规则对客户端可以读取的数据有限制,因此它们拒绝此操作 您需要通过与安全规则匹配的查询读取数据,以确保客户端请求的内容不超过安全规则允许的内容。大概是
db.collection('/hospitals')
.where("name", ">=", "")
.get()
.then(printResult)
请注意,这确实要求文档具有名称
字段,否则名称不能为空
有关详细信息,请参阅: