【发布时间】:2019-04-02 04:58:52
【问题描述】:
我的请求看起来很简单:使用 Firestore 规则限制子集合中的文档数量。
我已经知道使用.size() 可以知道数组的大小。所以,你可能会问为什么我不使用数组来存储我的项目?好吧,我希望“普通”用户不能更新我的父文档字段,但能够将文档添加到我的子集合中。
我已经尝试过这样做:
match /slots/{slot} {
allow read: if true;
allow write: if getRole() == 'ADMIN';
match /participants/{participant} {
allow read: if true;
allow create: if get(/databases/$(database)/documents/slots/$(slot)/participants).size() < 2;
allow delete: if participant.data.id == request.auth.uid || getRole() == 'ADMIN';
}
}
但是get(/databases/$(database)/documents/slots/$(slot)/participants) 不起作用,因为get() 只能用于获取单个文档。
也许我可以试试云功能……
我的问题有什么解决办法吗? 感谢您的帮助!
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security