Challenge - 5 Problems
Master of Firebase Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2: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 */ });
Attempts:
2 left
💡 Hint
Think about which method limits results to values less than a given number.
✗ Incorrect
In Firebase Realtime Database, endBefore(30) returns all records with 'age' less than 30. startAt(30) returns ages 30 and above. equalTo(30) returns only age 30. endAt(29) returns ages up to 29 inclusive, but 29 is less than 30, so it works similarly for integer ages.
❓ Architecture
intermediate2: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 */ });
Attempts:
2 left
💡 Hint
Remember that >= means greater than or equal to.
✗ Incorrect
The 'where' clause with '>=' returns documents where 'total' is 100 or more. '>' excludes 100. '<=' and '==' do not match the requirement.
❓ security
advanced2: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>; }Attempts:
2 left
💡 Hint
Check for exact equality between authenticated user ID and document ID.
✗ Incorrect
The '==' operator checks if the authenticated user's ID matches the document ID exactly, allowing access only to their own data. Other operators do not enforce this correctly.
✅ Best Practice
advanced2: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()
Attempts:
2 left
💡 Hint
Think about including the price 50 in the results.
✗ Incorrect
The '<=' operator includes all products priced less than or equal to 50. '<' excludes 50. '>' and '==' do not match the requirement.
🧠 Conceptual
expert3: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)?
Attempts:
2 left
💡 Hint
Consider how startAt and equalTo filter data differently.
✗ Incorrect
startAt(21) returns all users with age 21 or more. equalTo(21) returns only users whose age is exactly 21.