0
0
Firebasecloud~20 mins

Querying with where clause in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Where Clause Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Filtering documents with a single where clause
Given a Firestore collection users with documents containing fields age and city, what will be the output of this query?

db.collection('users').where('age', '>', 25).get()

Assuming the collection has these documents:
- {name: 'Alice', age: 30, city: 'NY'}
- {name: 'Bob', age: 22, city: 'LA'}
- {name: 'Carol', age: 27, city: 'NY'}
- {name: 'Dave', age: 24, city: 'SF'}
Firebase
db.collection('users').where('age', '>', 25).get()
A[{name: 'Alice', age: 30, city: 'NY'}, {name: 'Carol', age: 27, city: 'NY'}]
B[{name: 'Bob', age: 22, city: 'LA'}, {name: 'Dave', age: 24, city: 'SF'}]
C[{name: 'Alice', age: 30, city: 'NY'}, {name: 'Bob', age: 22, city: 'LA'}]
D[]
Attempts:
2 left
💡 Hint
Think about which users have age greater than 25.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in a Firestore where clause
Which option contains a syntax error in the Firestore query using where clause?
Firebase
db.collection('products').where('price' '>=', 100).get()
Adb.collection('products').where('price', '>=', 100).get()
Bdb.collection('products').where('price', '>=', '100').get()
Cdb.collection('products').where('price', '=>', 100).get()
Ddb.collection('products').where('price' '>=', 100).get()
Attempts:
2 left
💡 Hint
Check the commas and operator spelling in the where clause.
optimization
advanced
2:30remaining
Optimizing multiple where clauses in Firestore
You want to query a collection orders to find documents where status is 'shipped' and total is greater than 50. Which query is optimized and valid in Firestore?
Adb.collection('orders').where('status', '==', 'shipped' || 'total', '>', 50).get()
Bdb.collection('orders').where('status', '==', 'shipped').where('total', '>', 50).get()
Cdb.collection('orders').where('status' == 'shipped' && 'total' > 50).get()
Ddb.collection('orders').where('status', '==', 'shipped' && 'total', '>', 50).get()
Attempts:
2 left
💡 Hint
Firestore supports chaining multiple where clauses separately.
🧠 Conceptual
advanced
2:00remaining
Understanding Firestore where clause limitations
Which statement about Firestore where clause limitations is true?
AYou cannot combine <code>where</code> clauses with <code>orderBy</code> on different fields without an index.
BYou can use multiple inequality filters on different fields in a single query.
CFirestore allows <code>where</code> clauses with OR logic directly.
DYou can use <code>where</code> clauses with array fields using the '!=' operator.
Attempts:
2 left
💡 Hint
Think about Firestore indexing and query constraints.
🔧 Debug
expert
3:00remaining
Debugging a Firestore query with multiple where clauses
You run this query:
db.collection('employees').where('department', '==', 'sales').where('age', '<', 30).where('age', '>', 40).get()

What will happen when you run it?
AThe query throws an error because multiple inequality filters on the same field with conflicting conditions are not allowed.
BThe query returns employees in sales department with age between 30 and 40.
CThe query returns employees in sales department with age less than 30 and greater than 40.
DThe query returns all employees in sales department ignoring age filters.
Attempts:
2 left
💡 Hint
Check Firestore rules about multiple inequality filters on the same field.