sathishkumar
sathishkumar

Reputation: 1816

Is there any way to validate array in firestore rules

When i see my data in firebase console it will look like below

enter image description here

I am writing firestore security rules to protect data.

security rules:

     match /wallpost/{wallpostId} {
          allow read: if true;
          allow list: if request.query.limit <= 10;
          allow create, update, delete: if resource.data.createdBy == request.auth.uid && request.resource.data.createdBy is string && request.resource.data.description is string 
// && **HERE I WANT VALIDATE TAG - WHICH IS A ARRAY OF STRING** 
        }

Could anyone knows how to validate array of data in firestore.

(My Mind: If we cant validate array in firestore, anyone can inject huge junk data and hack firestore also. So we should not allow the user to write the array or object directly, instead use firestore function to do this mapping and arrange data in correct place)

Please help me...

Upvotes: 1

Views: 2666

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

If you want to allow reading the document if tag1 is in the tag field, you can do:

match /posts/{postID} {
  allow read: if 'tag1' in resource.data.tag
}

Also see:

Upvotes: 3

Related Questions