使用Firestore安全规则检查可选的日期和地图是否具有有效的类型
在 Firestore 安全规则中,我们可以检查可选字符串和列表的类型,如下所示:
function reviewFieldsAreValidTypes(docData) {
return docData.get('photo_url', '') is string &&
docData.get('tags', []) is list;
}
将使用什么作为可选时间戳的默认值?
docData.get('dateModified', ???) is timestamp;
还有可选地图?
docData.get('translated', ???) is map;
In Firestore security rules we can check the types of optional strings and lists as follows:
function reviewFieldsAreValidTypes(docData) {
return docData.get('photo_url', '') is string &&
docData.get('tags', []) is list;
}
What would one use as the default value for optional timestamps?
docData.get('dateModified', ???) is timestamp;
And for an optional map?
docData.get('translated', ???) is map;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们只需要设置正确类型的默认值即可。我们可以使用请求对象:
We just need to set a default value of the correct type. We can use the request object:
没有直接解决您的问题的解决方案,但是您可以选择使用下面已发布的代码的条件:
只需注意,请记住规则不是过滤编写查询以检索文档时。
There's no direct solution for your question, but you have an option to use a condition like the posted code below:
Just a note, keep in mind that rules are not filters when writing queries to retrieve documents.