我们的数据库结构如下:
trips
12345
toArea
radius: 150
name: "citycenter"
54321
toArea
radius: 250
name: "main street"
我们试图创建一些从文档中读取的规则:
match /chats/{trip} {
match /messages/{message} {
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
}
}
它工作正常
但是下一个规则不起作用:
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea.radius != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea.radius == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea["radius"] == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea["radius"] != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data["toArea.radius"] == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data["toArea.radius"] != null
我真的不明白它有什么问题,两个相反的规则(== null /!= null)怎么可能不起作用。我们如何在规则中使用torea.radius字段进行管理?
编辑(12/18/17):这些都已修复,所以这应该是Just Work™。
正如@hatboysam所提到的那样,您目前正在遇到两个我们正在迅速修复的错误:
get().data
只有在你的规则中某处提到resource.data
或request.resource.data
才有效(我们曾经支持get()
在不使用resource
的情况下返回data
,但这最终会产生问题,所以它在发布前就已经改变了)。toArea.radius
)被破坏了。1很容易解决:
match /chats/{trip} {
match /messages/{message} {
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
}
}
match /bogusPathThatWillNeverMatch {
allow read: if resource.data != null; // should never be true
}
1和2都将很快修复,敬请期待分辨率。