0

I have a highly concurrent application that will have lots of users and lots of concurrency problems. I don't need much from Firebase, but I would like to know if there is ANY way to have a "primary key violation" (or whatever you would call it in Firebase) to be thrown if someone tries to create an object with the same ID as one that already exists. Is this possible?

skb
  • 30,624
  • 33
  • 94
  • 146
  • Definitely. See http://stackoverflow.com/questions/25294478/how-do-you-prevent-duplicate-user-properties-in-firebase, http://stackoverflow.com/questions/20260476/what-firebase-rule-will-prevent-duplicates-in-a-collection-based-on-other-fields, http://stackoverflow.com/questions/26108341/firebase-security-rule-and-check-for-unique-records and https://calendee.com/2014/12/02/restricting-emails-or-mobile-number-checks-in-firebase/. All of them essentially fall into two camps: *either* use the unique property as the key *or* set up a secondary "index" node for the unique property. – Frank van Puffelen May 06 '15 at 04:22
  • Also [transactions](https://www.firebase.com/docs/web/guide/saving-data.html#section-transactions) and [security rules](https://www.firebase.com/docs/security/). Of those, security rules are the easiest and most secure, not relying on anything from the client. Transactions will prevent concurrent edits from a client, but not enforce that the data doesn't exist. – Kato May 06 '15 at 15:21

0 Answers0