Reputation: 79
I am wondering how do I check if a field is an integer or not. I know that we are able to convert a field entry to an integer with int(request.resource.data[field])
, but is there a way to check if request.resource.data[field]
is an integer, return true if it is, and false it isn't?
Upvotes: 1
Views: 1185
Reputation: 598740
You can check for type with the is
operator.
So:
request.resource.data[field] is int
Or
request.resource.data.field is int
I highly recommend checking out Doug's video on Data types and global objects in Firebase security rules, specifically the section on checking types.
Upvotes: 7