Manage a solution that can span multiple database technologies →mediumMultiple ChoiceObjective-mapped
PCDE Automatic indexing Practice Question
A company uses Firestore in Native mode and has a collection with many documents containing array fields. They want to index the array values to support queries like 'array-contains'. What is the correct approach?
⚠ Common exam trap
Candidates often confuse Firestore Native mode with Datastore mode. In Native mode, indexes are automatic; in Datastore mode, indexes must be manually configured. Also, 'index exemption' is for excluding fields, not adding them.
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
✓
No additional index configuration is required; arrays are automatically indexed
In Firestore Native mode, all fields are automatically indexed by default, including array fields. For array fields, the index includes each element, which allows queries using the `array-contains` operator to work without any additional configuration. Index exemptions are used to exclude specific fields from automatic indexing, not to enable indexing. Therefore, no action is required.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create an index exemption for the array field to enable indexing
Why it's wrong here
Incorrect. Index exemptions exclude fields from indexing, not enable them. Creating an exemption for the array field would prevent array-contains queries.
- ✗
Switch to Datastore mode and configure indexes manually
Why it's wrong here
Incorrect. Datastore mode requires manual index configuration and is not needed here. Native mode automatically indexes arrays.
- ✗
Create a composite index that includes the array field
Why it's wrong here
Incorrect. Composite indexes are for queries involving multiple fields. A simple array-contains query on a single field does not require a composite index.
- ✓
No additional index configuration is required; arrays are automatically indexed
Why this is correct
Correct. In Firestore Native mode, array fields are automatically indexed, so no additional configuration is needed for array-contains queries.
Go deeper
Related to this question
About these practice questions
This PCDE question is part of Courseiva's 1,446-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
3 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. A development team is using Firestore in Native mode. They want to ensure that queries on array fields return correct results. Which two actions should they take? (Choose TWO.)
easy- A.Create a composite index for every query involving array fields.
- B.Set index exemptions for arrays and maps to disable automatic indexing.
- ✓ C.Use the 'array-contains' operator only on indexed arrays.
- D.Manually create indexes for each array field in the Firestore console.
- ✓ E.Understand that array fields are automatically indexed as single-field indexes.
Why C: Firestore automatically creates single-field indexes for all fields, including array fields. This means the array-contains operator works without manual indexing, provided the field has not been excluded via index exemptions. However, to ensure queries return correct results, developers must understand that array fields are indexed by default (E) and that array-contains only works on indexed arrays (C). Option B is incorrect because disabling indexing via exemptions would prevent array-contains queries from working.
Variation 2. An application uses Cloud Firestore. The team notices that queries on a collection with an array field are slow. They want to create an index on the array field. What should they do?
medium- A.Create a collection group index on the field.
- ✓ B.Create a composite index on the array field and another field.
- C.Create an index exemption for the array field.
- D.Rely on the automatically created single-field index.
Why B: Cloud Firestore does not support single-field indexes on array fields. To enable efficient queries involving array fields, you must create a composite index that includes the array field along with another field. This allows Firestore to use the composite index for array-contains queries and other array operations, improving query performance.
Variation 3. A team is using Firestore in Native mode. They have a collection 'users' with an array field 'roles'. They need to query all users where roles contains 'admin'. What index configuration is required?
hard- A.Create a single-field index on roles with ascending order.
- ✓ B.Create an index exemption on the 'roles' field.
- C.Create a composite index on roles and the default field.
- D.No index is needed; Firestore automatically supports array-contains queries.
Why B: Firestore supports array membership queries using the 'array-contains' operator. An index exemption for the array field is required because Firestore does not automatically index array fields for array-contains queries. The exemption is created manually.
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.