0
0
Firebasecloud~10 mins

Comparison operators (==, <, >, >=, <=) in Firebase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Comparison operators (==, <, >, >=, <=)
Start Comparison
Evaluate Left Value
Evaluate Right Value
Apply Operator (==, <, >, >=, <=)
Result: True or False
Use Result in Query or Condition
Comparison operators check two values and return true or false, which helps decide what data to fetch or actions to take.
Execution Sample
Firebase
db.collection('users').where('age', '>=', 18).get()
This query fetches users whose age is 18 or older using the '>=' comparison operator.
Process Table
StepLeft ValueOperatorRight ValueEvaluationResult
1age field value (e.g., 20)>=1820 >= 18True
2age field value (e.g., 16)>=1816 >= 18False
3age field value (e.g., 18)==1818 == 18True
4age field value (e.g., 17)<1817 < 18True
5age field value (e.g., 19)<=1819 <= 18False
6Query applies filter only to documents where result is True
💡 Comparison stops after evaluating each document's field against the operator and value.
Status Tracker
VariableStartAfter Eval 1After Eval 2After Eval 3After Eval 4After Eval 5Final
age field valuevaries per document2016181719varies per document
Key Moments - 3 Insights
Why does 'age >= 18' return false for some users?
Because the user's age is less than 18, as shown in execution_table row 2 where 16 >= 18 evaluates to false.
Is '==' the same as '>=' or '<='?
'==' checks if values are exactly equal, while '>=' and '<=' check if values are greater or equal, or less or equal respectively, as shown in rows 3 and 1.
What happens if the field value is missing?
The comparison usually returns false because there is no value to compare, so the document is excluded from results.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of evaluating age = 17 with operator '<' and right value 18?
AError
BTrue
CFalse
DUndefined
💡 Hint
Check row 4 in the execution_table where 17 < 18 is evaluated.
At which step does the comparison 'age == 18' return true?
AStep 3
BStep 1
CStep 5
DStep 2
💡 Hint
Look at the operator and result columns in execution_table row 3.
If a user's age is 19, what is the result of 'age <= 18' comparison?
ATrue only if age is 18
BTrue
CFalse
DCannot determine
💡 Hint
Refer to execution_table row 5 where 19 <= 18 is evaluated.
Concept Snapshot
Comparison operators check two values and return true or false.
Operators: == (equal), < (less than), > (greater than), >= (greater or equal), <= (less or equal).
Used in Firebase queries to filter data.
Example: where('age', '>=', 18) fetches users 18 or older.
If comparison is false, document is excluded from results.
Full Transcript
Comparison operators in Firebase compare two values and return true or false. These operators include equal (==), less than (<), greater than (>), greater or equal (>=), and less or equal (<=). When you write a query like where('age', '>=', 18), Firebase checks each document's age field. If the age is 18 or more, the comparison returns true and the document is included. If not, it returns false and the document is excluded. This process repeats for each document in the collection. Understanding these operators helps you filter data effectively in Firebase.