Only allow unique values in Firebase Realtime Data

2019-07-09 08:43发布

问题:

This question already has an answer here:

  • How do you prevent duplicate user properties in Firebase? 2 answers
  • Firebase security rules to check unique value of a child #AskFirebase 1 answer

Here's my data structure:

root
---+ mydata
    |--- -KqI0uf--1-bD3oLlx2h:"Joe"
    |--- -Kdk0bf--1-bx0oLlb9a:"Mike"
    |--- -Kox8gf--1-b36onlT3h:"Eve"

How do I write a rule to only allow unique values in my Firebase Realtime Database?

For example, I don't want this to happen:

root
---+ mydata
    |--- -KqI0uf--1-bD3oLlx2h:"Boss"
    |--- -Kdk0bf-3-bx0oLlb9a:"Bob"
    |--- -Kox8gf1-b36onlT3h:"Dot"
    |--- -Kbx8gff-1-b92ksvT7:"Bob" // this should not exist