Bird
Raised Fist0
Firebasecloud~20 mins

Comparison operators (==, <, >, >=, <=) in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Firebase Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
Firebase Realtime Database: Query with < operator
You want to retrieve all users whose age is less than 30 from your Firebase Realtime Database. Which query will correctly return these users?
Firebase
firebase.database().ref('users').orderByChild('age').<operator>(30).once('value').then(snapshot => { /* handle data */ });
Afirebase.database().ref('users').orderByChild('age').endBefore(30).once('value')
Bfirebase.database().ref('users').orderByChild('age').startAt(30).once('value')
Cfirebase.database().ref('users').orderByChild('age').equalTo(30).once('value')
Dfirebase.database().ref('users').orderByChild('age').endAt(29).once('value')
Attempts:
2 left
💡 Hint
Think about which method limits results to values less than a given number.
❓ Architecture
intermediate
2:00remaining
Firestore: Filtering documents with >= operator
You want to get all orders with a total amount greater than or equal to 100 in Firestore. Which query correctly achieves this?
Firebase
firebase.firestore().collection('orders').where('total', '<operator>', 100).get().then(snapshot => { /* handle data */ });
Afirebase.firestore().collection('orders').where('total', '>=', 100).get()
Bfirebase.firestore().collection('orders').where('total', '>', 100).get()
Cfirebase.firestore().collection('orders').where('total', '<=', 100).get()
Dfirebase.firestore().collection('orders').where('total', '==', 100).get()
Attempts:
2 left
💡 Hint
Remember that >= means greater than or equal to.
❓ security
advanced
2:00remaining
Firestore Security Rules: Using == operator
You want to allow users to read their own profile document only if their user ID matches the document ID. Which security rule condition correctly enforces this?
Firebase
match /users/{userId} { allow read: if <condition>; }
Arequest.auth.uid == userId
Brequest.auth.uid < userId
Crequest.auth.uid != userId
Drequest.auth.uid >= userId
Attempts:
2 left
💡 Hint
Check for exact equality between authenticated user ID and document ID.
✅ Best Practice
advanced
2:00remaining
Choosing correct comparison operator in Firestore queries
You want to query Firestore for products priced less than or equal to $50. Which operator should you use in the where clause to get all products priced at $50 or less?
Firebase
firebase.firestore().collection('products').where('price', '<operator>', 50).get()
A'<'
B'<='
C'>'
D'=='
Attempts:
2 left
💡 Hint
Think about including the price 50 in the results.
🧠 Conceptual
expert
3:00remaining
Understanding Firebase Realtime Database query behavior with >= and == operators
Consider this Firebase Realtime Database query to find users with age greater than or equal to 21: firebase.database().ref('users').orderByChild('age').startAt(21).once('value') What will be the difference in results if you replace startAt(21) with equalTo(21)?
ABoth return users aged 21 and older
BstartAt(21) returns only users aged exactly 21; equalTo(21) returns users aged 21 and older
CstartAt(21) returns users aged 21 and older; equalTo(21) returns only users aged exactly 21
DBoth return only users aged exactly 21
Attempts:
2 left
💡 Hint
Consider how startAt and equalTo filter data differently.

Practice

(1/5)
1. Which comparison operator in Firebase queries checks if a field value is exactly equal to a given value?
easy
A. ==
B. <
C. >=
D. <=

Solution

  1. Step 1: Understand the purpose of each operator

    The operator == checks for exact equality, while <, >=, and <= check for less than, greater or equal, and less or equal respectively.
  2. Step 2: Identify the operator for exact equality

    Since the question asks for exact equality, the correct operator is ==.
  3. Final Answer:

    == -> Option A
  4. Quick Check:

    Exact equality operator = == [OK]
Hint: Use == to check if values are exactly the same [OK]
Common Mistakes:
  • Confusing == with assignment operator =
  • Using < or > for equality checks
  • Thinking >= means equal only
2. Which of the following is the correct Firebase query syntax to find documents where the field age is greater than 18?
easy
A. query.where('age', '==', 18)
B. query.where('age', '<', 18)
C. query.where('age', '>=', 18)
D. query.where('age', '>', 18)

Solution

  1. Step 1: Identify the operator for 'greater than'

    The operator for 'greater than' is >.
  2. Step 2: Match the operator with the correct syntax

    The correct syntax uses query.where('age', '>', 18) to filter documents where age is greater than 18.
  3. Final Answer:

    query.where('age', '>', 18) -> Option D
  4. Quick Check:

    Greater than operator = > [OK]
Hint: Use '>' for values strictly greater than target [OK]
Common Mistakes:
  • Using '==' instead of '>'
  • Confusing '>=' with '>'
  • Using '<' when wanting greater values
3. Given this Firebase query: query.where('score', '>=', 50).where('score', '<', 70), which scores will be included in the results?
medium
A. Scores greater than or equal to 50 and less than 70
B. Scores greater than 50 and less than or equal to 70
C. Scores equal to 50 or equal to 70
D. Scores equal to 50 and less than 70

Solution

  1. Step 1: Analyze the first condition

    The first condition score >= 50 includes scores 50 and above.
  2. Step 2: Analyze the second condition

    The second condition score < 70 includes scores less than 70, excluding 70 itself.
  3. Step 3: Combine both conditions

    Only scores that satisfy both conditions are included: scores greater than or equal to 50 and less than 70.
  4. Final Answer:

    Scores greater than or equal to 50 and less than 70 -> Option A
  5. Quick Check:

    Range includes 50 ≤ score < 70 [OK]
Hint: Combine >= and < for range queries [OK]
Common Mistakes:
  • Including 70 when using '<' operator
  • Confusing '>' with '>='
  • Thinking 'or' instead of 'and' between conditions
4. You wrote this Firebase query: query.where('price', '=>', 100). Why does it cause an error?
medium
A. Because 'price' field cannot be compared
B. Because 100 should be a string, not a number
C. Because '=>' is not a valid comparison operator in Firebase queries
D. Because the operator should be '<=' instead

Solution

  1. Step 1: Check the operator syntax

    The operator '=>' is not a valid Firebase comparison operator. The correct operator for 'greater than or equal' is '>='.
  2. Step 2: Understand Firebase operator rules

    Firebase only supports specific operators: ==, <, >, <=, and >=. Using any other operator causes a syntax error.
  3. Final Answer:

    '=>' is invalid operator causing error -> Option C
  4. Quick Check:

    Use >=, not => for greater or equal [OK]
Hint: Use >=, not => for greater or equal [OK]
Common Mistakes:
  • Typing => instead of >=
  • Using strings instead of numbers for numeric fields
  • Assuming all operators are valid
5. You want to query Firebase documents where the field temperature is between 20 and 30 inclusive. Which query correctly uses comparison operators to achieve this?
hard
A. query.where('temperature', '>', 20).where('temperature', '<', 30)
B. query.where('temperature', '>=', 20).where('temperature', '<=', 30)
C. query.where('temperature', '==', 20).where('temperature', '==', 30)
D. query.where('temperature', '<=', 20).where('temperature', '>=', 30)

Solution

  1. Step 1: Understand inclusive range requirements

    Inclusive means including both 20 and 30 values.
  2. Step 2: Choose operators that include boundary values

    >= includes 20 and <= includes 30, so these operators match the requirement.
  3. Step 3: Verify the combined query

    The query query.where('temperature', '>=', 20).where('temperature', '<=', 30) correctly filters temperatures from 20 to 30 inclusive.
  4. Final Answer:

    query.where('temperature', '>=', 20).where('temperature', '<=', 30) -> Option B
  5. Quick Check:

    Inclusive range uses >= and <= [OK]
Hint: Use >= and <= for inclusive ranges [OK]
Common Mistakes:
  • Using > and < excludes boundary values
  • Using == twice filters only exact matches
  • Reversing operators causing empty results
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard