最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I create a firestore security rule that allows only "count" aggregation queries? - Stack Overflow

programmeradmin10浏览0评论

I wish users to be able to query how many documents match a given where clause, without resorting to Cloud Functions, and without them being allowed to retreive the document content.

For example, under /users/{uid} I have documents like so:

{
  "private_data": ...
  "group": "groupname"
}

The firestore rules:

match /users/{uid} {
  // Allow  a user to read only his own data
  allow read: if request.auth != null && request.auth.uid == uid;
  
  // Allow a user to know how many users are in a specified group
  allow list: if request.<has group specified in where clause> && request.<is count aggregation>
}

I wish users to be able to query how many documents match a given where clause, without resorting to Cloud Functions, and without them being allowed to retreive the document content.

For example, under /users/{uid} I have documents like so:

{
  "private_data": ...
  "group": "groupname"
}

The firestore rules:

match /users/{uid} {
  // Allow  a user to read only his own data
  allow read: if request.auth != null && request.auth.uid == uid;
  
  // Allow a user to know how many users are in a specified group
  allow list: if request.<has group specified in where clause> && request.<is count aggregation>
}
Share Improve this question asked Feb 5 at 3:25 BharelBharel 26.9k7 gold badges49 silver badges95 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

At the moment, according to the Firestore security rules' specification, I believe this feature does not exist.

The only way is to resort to Cloud Functions, Cloud Run or a different backend solution.

发布评论

评论列表(0)

  1. 暂无评论