我有一个像上面的结构。我要实现的是在chat_room用户中只能在用户数组中将此uid.isActive == true
写入rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow update, delete: if request.auth != null && request.auth.uid == userId;
allow create, read: if request.auth != null;
}
match /chats/{chatId} {
allow read, write: if request.auth.uid != null;
match /chat_room/{roomId} {
allow read, write: if request.auth.uid != null;
}
}
}
}
答案 0 :(得分:1)
听起来像你想要的
match /chat_room/{roomId} {
allow read, write: if get(/databases/$(database)/documents/chats/$(chatId)).data.users[request.auth.uid].IsActive == true;
}
因此,在写入chat_room
文档时,这将加载父文档,然后检查该用户是否在其中被标记为活动用户。