André
André

Reputation: 783

Firestore Rules - Datatype Validation

I've read multiple questions in Stack Overflow and the documentation but I couldn't find multiple validations that I can imagine that exist.

Per example, it is possible to check if request.resource.data.description is string but can is it possible to do the same when it comes to number, float, timestamp or even array/list? I couldn't even find the string one in the documentation so I can imagine it is missing more than just that one.

Upvotes: 12

Views: 2903

Answers (2)

Dmytro
Dmytro

Reputation: 5701

As of October 2024, the following types for Firestore are valid (Firestore rules reference):

  • bool
  • bytes
  • constraint
  • duration
  • float
  • int
  • latlng
  • list (this one is for arrays)
  • vector
  • set
  • number
  • map (this one is for objects)
  • string
  • timestamp
  • path
  • map_diff

To validate a field type, you can use a similar notation:

request.resource.data.user_comments is list

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317392

You might want to watch my video on data types in Firebase security rules. In it, I list all the different data types that you can check:

value is bool
value is int
value is float
value is number
value is string

value is list
value is map

value is timestamp
value is duration
value is path
value is latlng

Upvotes: 38

Related Questions