我是否需要对要访问的文档的每个字段执行获取



我看到要在安全规则中获取文档的字段,必须使用 get。下面的示例演示如何获取用户集合中某个文档的"admin"字段。如果我想获取另一个字段,我是否必须执行另一个 get 请求,或者我可以只执行一个 get 请求并获取文档中所需的所有字段。

这是我在文档中引用的示例。

https://firebase.google.com/docs/firestore/security/rules-conditions

service cloud.firestore {
match /databases/{database}/documents {
match /cities/{city} {
// Make sure a 'users' document exists for the requesting user before
// allowing any writes to the 'cities' collection
allow create: if exists(/databases/$(database)/documents/users/$(request.auth.uid))
// Allow the user to delete cities if their user document has the
// 'admin' field set to 'true'
allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true
}
}
}

是的,你必须写另一个 get((。 Firestore 安全规则中没有变量,因此您无法存储 get(( 的内容以便多次使用其数据。

多次访问同一文档可能不会产生多次读取费用。 文档指出:

某些文档访问调用可能会被缓存,并且缓存的调用不计入限制。

最新更新