我有下一个firestore规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{usuarios=**} {
allow write: if get(/usuarios/$(request.auth.uid)).data.level == 0 || get(/usuarios/$(request.auth.uid)).level == 0;
}
}
}当我尝试这个查询时,我得到了"permission-denied“:
firebase.firestore().collection('usuarios').doc(uid).set({...});这实际上是我的数据库:

pd:我想在我的数据库中添加关于新用户的信息(通过他的UID)
发布于 2017-12-24 16:13:18
这将是非常昂贵和低效的,因为您是按get请求付费的。相反,您应该像定义数据库结构一样编写规则。我的意思是:
service cloud.firestore {
match /databases/{database}/documents {
match /usuarios/{uid} {
// Give write access to any field within the document who's id is the uid
// Add other validation as needed.
allow write: if uid == request.auth.uid
// Give admin access to anyone who's `level == 0`
// Make sure to add the `databases...` boilerplate
|| get(/databases/$(database)/documents/usuarios/$(request.auth.uid)).data.level == 0;
// If necessary, give access to sub-collections.
// (We can't do it for uid or it will become a path object that we can't use as a string.)
/{sub=**} {
allow write: if uid == request.auth.uid;
}
}
}
}如果你想看到完全清除的规则做着非常相似的事情,我有一个open source exemple。干杯!
https://stackoverflow.com/questions/47958595
复制相似问题