You have a Firestore collection named users with documents containing fields age (number) and status (string). Which query will return all users older than 25 with status exactly 'active'?
const query = firestore.collection('users').where('age', '>', 25).where('status', '==', 'active');
Remember that where filters must match the exact condition you want. The array-contains operator is for arrays, not strings.
Option B correctly filters users with age greater than 25 and status exactly 'active'. Option B uses wrong operators, option B filters for age less than 25, and option B incorrectly uses array-contains on a string field.
You want to run a Firestore query filtering by category and ordering by createdAt. What must you do to ensure the query runs efficiently?
Compound queries with filters and orderings require composite indexes matching the filter and order fields.
Firestore requires a composite index matching the filter field category and the order field createdAt. The order of fields and their sort directions must match the query.
You want to allow users to read only documents from the orders collection where the userId field matches their own user ID. Which Firestore security rule enforces this?
match /orders/{orderId} {
allow read: if resource.data.userId == request.auth.uid;
}Check that the document's userId matches the authenticated user's ID.
Option A correctly restricts reads to documents where the userId matches the current user. Option A allows all authenticated users to read all documents. Option A denies access to matching users. Option A only allows admin user.
You have a query that fetches all documents from a large collection but only needs the name and email fields. How can you reduce data transfer costs?
Fetching only required fields reduces data transferred and cost.
Option C uses Firestore's select method to fetch only specified fields, reducing data and cost. Option C fetches unnecessary data. Option C limits documents but not fields. Option C orders results but does not reduce data size.
Which of the following Firestore queries will cause an error due to Firestore's query limitations?
firestore.collection('products')
.where('price', '>', 10)
.where('price', '<', 50)
.where('category', '==', 'books')Firestore allows multiple range filters on the same field but only one field with range filters per query.
Option D is correct because Firestore supports multiple range filters on the same field. Option D is incorrect; multiple range filters on different fields are not allowed, but on the same field is allowed. Option D is incorrect; combining equality and range filters on different fields is allowed. Option D is partially true but does not cause an error by itself.
