Courseiva

PCDE Practice Question: Manage a solution that can span multiple database technologies

An application uses Firestore in Native mode. The query filters on two fields: 'status' (string) and 'created_date' (timestamp). The query returns results but the billing shows high document reads. What is the most likely cause?

⚠ Common exam trap

A common pitfall is the misconception that missing ORDER BY or using array-contains causes high reads, when in fact the real culprit is the lack of a composite index for inequality filters combined with equality filters.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The query is using an inequality filter on 'created_date' which requires a composite index.

In Firestore Native mode, queries that apply an inequality filter (e.g., >=, >, <, !=) on a field automatically require a composite index on both the equality filter field and the inequality filter field to avoid a full collection scan. Without that composite index, Firestore performs a back-end scan of all documents matching the equality filter, then applies the inequality filter in memory, resulting in high document reads. Option A correctly identifies that the inequality filter on 'created_date' is the most likely cause of the excessive reads because it forces Firestore to read and discard many documents that do not satisfy the timestamp condition.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The query is using an inequality filter on 'created_date' which requires a composite index.

    Why this is correct

    Correct. Queries with equality on one field and inequality on another need a composite index to avoid scanning all documents.

  • The query is using 'array-contains' which always scans the entire collection.

    Why it's wrong here

    array-contains can use existing indexes if properly indexed.

  • The 'status' field is not indexed because single-field indexes are not automatic.

    Why it's wrong here

    Single-field indexes are automatic in Native mode.

  • The query is missing an ORDER BY clause causing a full scan.

    Why it's wrong here

    Missing ORDER BY does not cause a full scan if indexes are used.

About these practice questions

One of 1,446 original PCDE practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

8 more ways this is tested on PCDE

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Your Firestore database in Native mode is used by a mobile app. You need to query a collection where documents are filtered by two fields: 'status' (string) and 'createdAt' (timestamp). The query is not performing as expected. What action is required?

medium
  • A.Create an index exemption for the collection to allow multi-field queries.
  • B.Add a third field to the query to make it more specific.
  • C.Create a composite index on the 'status' and 'createdAt' fields.
  • D.Ensure that single-field indexes exist for both 'status' and 'createdAt'.

Why C: Firestore in Native mode requires a composite index to efficiently query documents filtered by multiple fields, such as 'status' and 'createdAt'. Without this index, the query may fail or perform poorly, as Firestore cannot combine separate single-field indexes for equality and range filters. Option C is correct because creating a composite index on both fields enables the query to run as expected.

Variation 2. A company uses Firestore in Native mode for their application. They need to query a collection where documents must match a specific field value and be sorted by a different field. The query filters on 'status' and orders by 'timestamp'. What should the engineer do to ensure the query performs optimally?

medium
  • A.Create an index exemption to improve query performance.
  • B.Use a collection group query to bypass index requirements.
  • C.Rely on automatic single-field indexes; they will cover the query.
  • D.Create a composite index on the 'status' and 'timestamp' fields.

Why D: Firestore requires a composite index when a query includes both an equality filter on one field (status) and an order by clause on a different field (timestamp). Without this composite index, Firestore cannot efficiently satisfy both the filter and the sort order in a single index scan, leading to suboptimal performance or query failure. Creating a composite index on (status, timestamp) allows Firestore to use a single index to match the filter and return results in the requested order.

Variation 3. A gaming company uses Firestore in Native mode to store player profiles and game state. They need to query the data by both 'playerId' and 'lastLoginTimestamp' sorted descending. The current index configuration is automatic. How should they configure indexing to support this query efficiently?

hard
  • A.Create two separate single-field indexes: one on 'playerId' and one on 'lastLoginTimestamp'
  • B.Use an exemption to remove automatic indexing on 'playerId' and rely on single-field indexes
  • C.Use the automatic index configuration; Firestore will create the necessary composite index automatically
  • D.Create a composite index on 'playerId' ascending and 'lastLoginTimestamp' descending

Why D: Firestore automatically creates single-field indexes for all fields. For queries with ordering on two fields, a composite index is required. The composite index must include both fields in the correct order (ascending or descending).

Variation 4. A developer wants to add a composite index in Firestore to support a query that filters on two fields: 'status' (equality) and 'createdAt' (range). How should the index be configured?

easy
  • A.Create a composite index with fields 'status' (ascending) and 'createdAt' (ascending).
  • B.No index is needed; single-field indexes are automatically created.
  • C.Create a composite index with fields 'createdAt' (ascending) and 'status' (ascending).
  • D.Add an index exemption on the 'status' field to force index creation.

Why A: Firestore requires a composite index when a query combines an equality filter on one field with a range filter on another. The index must list the equality field first ('status') followed by the range field ('createdAt'), with ascending order for both to support the range query efficiently. This matches the Firestore index definition rules for composite indexes.

Variation 5. A developer is building an application that uses Firestore (in Datastore mode). The application needs to query data across two properties: 'status' and 'timestamp', with an equality filter on 'status' and a range filter on 'timestamp'. Which three steps are required to support this query efficiently? (Choose THREE.)

medium
  • A.Ensure that single-field indexes exist for both 'status' and 'timestamp'
  • B.Enable automatic composite index creation in Firestore settings
  • C.Create an index exemption for the 'timestamp' field
  • D.Create a composite index on the 'status' and 'timestamp' fields
  • E.Use gcloud alpha firestore indexes composite create to define the index

Why A: Firestore (in Datastore mode) requires single-field indexes to be defined for each property used in a query, even when a composite index is also present. Without a single-field index on 'status' and 'timestamp', the query engine cannot efficiently evaluate the equality and range filters, leading to full table scans or query failures.

Variation 6. Your Firestore database in Native mode contains a collection with millions of documents. You need to query documents where the 'tags' field (an array) contains the string 'urgent'. What must you ensure in your index configuration?

medium
  • A.No additional index configuration is required; Firestore automatically creates the necessary index for array fields.
  • B.Ensure the 'tags' field is not indexed, and then create a composite index with the array-contains filter.
  • C.Create an index exemption for the 'tags' field to enable array queries.
  • D.Create a composite index on 'tags' and '__name__' for the collection.

Why A: Firestore automatically creates a single-field index for array fields. However, to query array-contains, you need an index on the field with the array-contains filter. Firestore automatically creates a single-field index for the 'tags' field, so no additional index is needed. If the query includes additional equality clauses, a composite index may be required, but for a simple array-contains, it's automatic.

Variation 7. A company uses Firestore in Native mode. They have a collection with 1 million documents and frequently run queries that filter on two fields: status and createdAt. The queries are slow. What should the team do?

hard
  • A.Create a composite index on (status, createdAt)
  • B.Create an index exemption for the status field
  • C.Use the Datastore mode instead
  • D.Add an index exemption for the createdAt field

Why A: Firestore creates single-field indexes automatically but for multi-field queries, a composite index must be created manually. Without it, queries may be slow or fail.

Variation 8. A company has a Firestore database in Native mode. They need to run a query that filters on two fields (status and date) and orders by date. The query is slow and returns an error that a matching index is missing. What must the engineer do to resolve this?

hard
  • A.Enable single-field indexes for both fields; Firestore will automatically use them.
  • B.Rewrite the query using 'IN' clauses to avoid the need for a composite index.
  • C.Create a composite index on status and date in the Firebase Console or using gcloud.
  • D.Change the database to Datastore mode, which does not require indexes.

Why C: Firestore requires a composite index on both the equality filter field (status) and the order field (date) when a query uses equality filters on one field and an order on another. Without this composite index, the query cannot be executed efficiently and returns an error. Creating the composite index via the Firebase Console or gcloud CLI resolves the issue.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCDE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCDE exam.