Tutorial: Security rules API

Step by stepSecurity Security rules API

RuleDataSnapshot

Presentation

This is the object type of predefined variables data,newData and root.

Methods

val()
  • No argument
  • return value: the value (Number, Boolean, String or Null)
child()
  • Arguments:
    • childPath : String
  • return value: a RuleDataSnapshot at subPath childPath
parent()
  • No argument
  • return value: a RuleDataSnapshot for parent path
hasChild()
  • Arguments:
    • childPath : String
  • return value: a boolean indicating if a child at that subpath exists (and is not null, which is the same for webcom)
hasChildren()
  • Arguments:
    • (optionnal) children : array of String
  • return value: a boolean indicating if children at that path exists

If no argument is provided, it returns true if at least one child exists. If an array is provided, it returns true if all children in array exist.

exists()
  • No argument
  • return value: a boolean indicating this path exists (ie. if this RuleDataSnapshot is not null)
isNumber()
  • No argument
  • return value: a boolean indicating if the data is a number
isString()
  • No argument
  • return value: a boolean indicating if the data is a string
isBoolean()
  • No argument
  • return value: a boolean indicating if the data is a boolean