Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a composed primary key using cloud firestore in firebase?

I'm new to firebase and I'm trying to use it in a small application. I'm used to work with relational db and it's weired for me the concept of document and collections of firebase because I didn't work with NoSql before. I have a form which consists of firstName, lastName, age, gender and other attributes. I want to make a constraint that prohibit to enter two different users with the same firstName and lastName. I choose the cloudfirestore for different reasons such as :

  1. Offline support for iOS, Android, and web clients.
  2. Indexed queries with compound sorting and filtering.
  3. Atomic write and transaction operations.

as mentioned in Choose a Database: Cloud Firestore or Realtime Database .

However in the cloudfirestore and under the tab Rules I have these lines:

service cloud.firestore {
match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

I need to add some validations or rules such as in the realtime database like Understand Firebase Realtime Database Rules.

Is there any sections that cover this part of validations rules in cloudfirestore that I missed? Any link or proposition will be welcome.

like image 603
Slim Avatar asked Jan 29 '26 15:01

Slim


1 Answers

There are no separate validation rules in Cloud Firestore. Instead you'll write the validation logic as part of the write rules.

See the section on data validation in the Firebase documentation for more information, and some examples.

like image 57
Frank van Puffelen Avatar answered Feb 01 '26 13:02

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!