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

Viewed 4059

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.

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.

Related