2016-11-09 52 views
0

编辑:想通了。只要它们似乎覆盖了预先存在的值,多位置更新就不会像更新一样工作。Firebase多位置更新处理安全规则的方式不同吗?

我很难搞清楚多位置更新的安全规则。到现在为止我有这个代码

return this.userProfileRef.child(firebase.auth().currentUser.uid).update(profileData); 

更新FB,其中profileData是含有某些领域对象的用户配置文件。

当我尝试执行相同的操作,但以可以添加更多写入操作(多位置更新)的方式写入时,出现验证错误。

var updateData = {}; 
updateData['users/' + firebase.auth().currentUser.uid] = profileData; 
return firebase.database().ref().update(updateData); 

我的安全规则

{ 
    "rules": { 
    ".write": "true", 
    ".read": "true", 
    "users": { 
     "$uid": { 
     ".read": "$uid === auth.uid", 
     ".write": "!data.exists() || (data.exists() && auth.uid === $uid)", 
     "profileStatus": { 
      ".validate": "!data.exists() || (newData.parent().hasChildren(['firstName', 'dateOfBirth', 'gender', 'lookingForGender', 'lookingForAgeMin', 'lookingForAgeMax', 'lookingForRadius']) && data.val() === 'incomplete' && newData.val() === 'awaitingVerification')" 
     } 
    } 
    } 
} 

在验证失败profileStatus,当我做如上所写的多位置更新,而是将当我做一个“正常”的更新。

有人可以帮忙,并告诉我我在这里失踪。 fb处理多位置更新时涉及到安全规则吗?

谢谢。

回答

0

好的,回答我自己的问题。看起来,多路径更新更像是一个多路径集合,因此它覆盖了导致我的验证失败的现有值。

我仍然对这个问题感到困惑...继这里的firebase博客后,我想,它会像更新一样。

在我的例子中,我有一个预先存在的键叫做dateOfBirth。当我运行多更新时,此密钥会被删除