【发布时间】:2021-03-02 20:11:55
【问题描述】:
我的问题
是否可以创建 firebase 规则,以便用户可以read 文档中的某些数据字段但 not read 同一文档中的其他规则?我问这个问题是因为我想让用户能够从文档中查询数据,但只能查询文档中的某些字段。
例如
假设您在故事文档中有以下数据:/stories/{storyid}
{
title: "A Great Story",
content: "Once upon a time...",
author: "some_auth_id",
published: false
}
在下面的示例中,我尝试创建一个规则,以便用户可以read/query 文档的作者(但不能是文档的其他字段 - 例如标题)。
请注意,我添加了 /stories/{storyid}/{author}
service cloud.firestore {
match /databases/{database}/documents {
match /stories/{storyid}/{author} {
allow read: if request.auth != null;
}
}
}
我将如何创建这样的规则?
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security