我是第一次使用firestore,我有一个问题,如果消息发送时间少于5分钟,我想允许读取,但它不起作用。
service cloud.firestore { match /databases/{database}/documents { match /locations/{allDocuments=**} { allow read: if request.time < Timestamp.fromMillis(resource.data.timestamp) + duration.time(0, 5, 0, 0) allow write: if true; } } }
每个数据都有一个子名称"timestamp“,值是一个类似于"1554710156002”的数字。
在这个读取条件下,我的应用程序不能读取任何东西,但它可以写入。有人知道问题出在哪里吗?
发布于 2019-04-08 16:39:38
尝试使用duration.time(hours, minutes, seconds, nanos) (文档化的here)来操作timestamps
duration.time(0, 5, 0, 0)此外,我个人的偏好是将持续时间放在(固定的)资源创建时间之后,这使得我更容易对其进行推理。
你的代码会变成
allow read: if request.time < resource.data.timestamp + duration.time(0, 5, 0, 0);(注意:我没有验证这一点,这是假设您的时间戳实际上是一个timestamp)
https://stackoverflow.com/questions/55568989
复制相似问题