2016-12-03 66 views
1

我一对夫妇的火力地堡数据库验证规则方面的不明确,以及已经read the documentation a couple of times我的具体情况/问题如下:使用的多个验证规则

我的数据方案是这样的:

{ 
    "aNumber" : 0.794180524700695, 
    "clicks" : 11 
} 

我目前的验证规则是这样的:

{ 
    "rules": { 
    ".validate": "newData.child('aNumber').isNumber()", 
    ".read": true, 
    ".write": true  
    } 
} 

这个规则目前允许“aNumber的”,如果它是一个数字写,但我会也想验证字段“点击”是一个数字。

我尝试使用和操作员(& &):

{ 
    "rules": { 
    ".validate": "newData.child('aNumber').isNumber() && 
       newData.child('clicks').isNumber()", 
    ".read": true, 
    ".write": true  
    } 
} 

但是,当我只更新一个字段失败:

{ 
"aNumber": 2 
} 

我将如何验证这个? ,一般验证多个独立领域的好方法是什么?

感谢

回答

3

所以经过一些尝试我找到了答案,以我自己的问题:

我的新规则是这样的:

{ 
"rules": { 
    ".read": true, 
    ".write": true, 
    "aNumber": { 
     ".validate": "newData.isNumber()" 
    }, 
    "clicks": { 
     ".validate": "newData.isNumber()" 
    }     
} 
} 

因此,而不是全球验证了特定的子节点,验证发生在规则中的特定节点级别,这对某些人来说可能是显而易见的,但是我花了一些时间才意识到。

+0

如果我想把它放在数据库中的特定目录中,我只需要另一个括号括起来? – CraftedGaming