0

I am working on a project where I need to limit the answers to a specific post. I am trying to create a rule where the write tag allows or not the operation based in the amount of existing answers. The actual JSON looks like this:

"root": {
  "posts": {
     "$post_id": {
       // all other post stuff here
       answers: { // <== this is the path that i must allow or not the write operation based on the child node count
        "$userId_thatAnswered": { //user object here }
       }
     }
  }
}

does anyone know how I could perform this security?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Khael Bubniak
  • 152
  • 2
  • 8
  • 1
    Kato answered something like this a while ago. See https://stackoverflow.com/questions/22644202/limit-number-of-records-that-can-be-written-to-a-path-reference-other-paths-in – Frank van Puffelen Jan 22 '20 at 15:44

1 Answers1

1

There are no child counts available in Firebase security rules. If you need to use a child count, you have to keep track of that value yourself, and put it in your database, so that you can reference it in your rules.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441