Firestore规则,查询和结构化数据

问题描述

我有一款使用Firestore进行多人游戏保存的游戏。

基本上每个文档都采用这种格式($表示20个字符的p随机ID)

$savegame = {
  users = [$user1,$user2]  
  info = {turn: 2,}
  gamestate = {longjsonstring} 
} 

我使用

查询数据
firebase.firestore().collection('savegamescollection').where('users','array-contains',firebase.auth().currentUser.uid)

我想使用Firestore规则来仅允许游戏中的人更新保存,我找不到找到检查Firestore规则中的用户数组的方法。

所以我所做的是(>表示集合)

savegame = {
  > usercol = { $user1,$user2 }   - line A
  users = [user1,user2]           - line B
...
} 

我使用规则

match /savegamescollection/{doc} { 
allow read,write: if exists(/databases/$(database)/documents/savegamescollection/$(doc)/usercol/$(request.auth.uid));

这确实有效,但是它有很多麻烦和丑陋。 我将相同的数据复制为数组中的元素和文档ID。

有没有一种方法可以在数据结构(上面的A和B)中使用这些行之一来允许查询和规则都起作用。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)