Operators and Functions
This chapter provides a detailed reference to the operators and built-in functions supported in Oracle Backend with Firebase APIs security rule expressions. These tools allow developers to write expressive, conditional logic that governs access to backend resources.
Operators
Operators are used to perform comparisons, logical evaluations, and arithmetic operations within rule conditions.
Logical Operators
| Operator | Description | Example |
|---|---|---|
!a |
Logical NOT | !request.auth.email_verified denies access if email is not verified |
a && b |
Logical AND | request.auth != null && resource.data.uuid == request.auth.uid |
a || b |
Logical OR This operator returns |
resource.data.isPublic == true || request.auth.uid == resource.data.ownerId |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
a == b |
Equal | resource.data.category == "Dessert" |
a != b |
Not equal | resource.data.category != "Dessert" |
a > b |
Greater than | resource.data.views > 1000 |
a >= b |
Greater than or equal | resource.data.views >= 1000 |
a < b |
Less than | resource.data.views < 1000 |
a <= b |
Less than or equal | resource.data.views <= 1000 |
a in b |
Value a exists in list b |
"Dessert" in resource.data.tags |
a is type |
Type check (For example, is string) |
resource.data.title is string |
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
a + b |
Addition | resource.data.views + 1 |
a - b |
Subtraction | resource.data.views - 1 |
a * b |
Multiplication | resource.data.price * 2 |
a / b |
Division | resource.data.total / resource.data.count |
Additional Operators
| Operator | Description | Example |
|---|---|---|
a[i] |
Indexing operator This operator accesses the element at index |
request.resource.data.tags[0] == "chocolate" checks if the first tag in the tags array is "chocolate". |
a.f |
Field access operator This operator accesses the field |
|
Built-in Functions
Oracle Backend with Firebase APIs security rules support a rich set of functions across different data types.
String Functions
| Function | Description | Example |
|---|---|---|
lower() |
Converts to lowercase | "Burger".lower() == "burger" |
upper() |
Converts to uppercase | "Burger".upper() == "BURGER" |
matches() |
Regex match | "Chocolate Chip,Corn Flour".matches(".*Flour.*") == true |
replace() |
Replace substring | "ChocolateChip".replace("Chip", "Coco") == "ChocolateCoco" |
split() |
Split string into list | "Chocolate,Flour".split(",") == ["Chocolate", "Flour"] |
trim() |
Remove white (blank) space | " Chocolate ".trim() == "Chocolate" |
size() |
String length | "Chocolate".size() == 9 |
List Functions
| Function | Description | Example |
|---|---|---|
concat() |
Merge lists | ["a"].concat(["b"]) == ["a", "b"] |
hasAll() |
All elements exist | ["a", "b"].hasAll(["a", "b"]) == true |
hasAny() |
Any element exists | ["a", "b"].hasAny(["b", "c"]) == true |
hasOnly() |
Only specified elements exist | ["a", "b"].hasOnly(["a", "b", "c"]) == true |
size() |
List length | ["a", "b"].size() == 2 |
Timestamp Functions
| Function | Description | Example |
|---|---|---|
year() |
Extract year | request.time.year() == 2025 |
month() |
Extract month | request.time.month() == 11 |
day() |
Extract day | request.time.day() == 14 |
dayOfWeek() |
Day of week | request.time.dayOfWeek() == 5 |
dayOfYear() |
Day of year | request.time.dayOfYear() == 318 |
hours() |
Extract hour | request.time.hours() >= 9 |
minutes() |
Extract minutes | request.time.minutes() < 30 |
seconds() |
Extract seconds | request.time.seconds() < 60 |
nanos() |
Extract nanoseconds | request.time.nanos() == 0 |
toMillis() |
Convert to milliseconds | request.time.toMillis() > 1600000000000 |
Math Functions
| Function | Description | Example |
|---|---|---|
abs() |
Absolute value | abs(-5) == 5 |
ceil() |
Round up | ceil(4.2) == 5 |
floor() |
Round down | floor(4.8) == 4 |
pow() |
Power | pow(2, 3) == 8 |
round() |
Round to nearest | round(4.6) == 5 |
sqrt() |
Square root | sqrt(16) == 4 |
Indexing and Slicing
| Operation | Example |
|---|---|
| Access element | request.resource.data.tags[0] == "chocolate" |
| Slice list | request.resource.data.tags[0:2] == ["chocolate", "chips"] |