Courseiva
Indexing and Performance →mediumMultiple Select

C100DBA Indexing and Performance Practice Question

A DBA is designing indexes for a collection that stores user activity logs. The collection has fields: user_id, action, timestamp, and metadata (an embedded document). The most common queries are: (1) find all actions for a given user_id sorted by timestamp descending; (2) find all users who performed a specific action within a time range. Which TWO indexes would best support these queries? (Choose two.)

⚠ Common exam trap

The trap here is creating a single compound index that attempts to cover both queries but fails to support the sort in query (1) because of an extra field in between.

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

✓

{ user_id: 1, timestamp: -1 }

The two indexes that best support the queries are { user_id: 1, timestamp: -1 } for query (1) and { action: 1, timestamp: 1 } for query (2). The first provides an equality match on user_id and a sort on timestamp, while the second provides an equality match on action and a range on timestamp. These indexes align with the equality-sort and equality-range patterns, ensuring efficient index usage.

Answer analysis

Option-by-option breakdown

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

  • ✗

    { metadata: 1 }

    Why it's wrong here

    Indexing the embedded document metadata as a whole is rarely useful for these queries, as they do not filter on metadata. Such an index would not support the common query patterns and would add unnecessary overhead.

  • ✓

    { user_id: 1, timestamp: -1 }

    Why this is correct

    This index supports query (1) by providing an equality match on user_id and a sort on timestamp descending. The index prefix is user_id, and the sort field follows, so the index can be used efficiently for both filtering and sorting, avoiding an in-memory sort.

  • ✗

    { user_id: 1, action: 1, timestamp: -1 }

    Why it's wrong here

    This compound index could support query (1) if action is not used, but the index prefix user_id is equality and then action is not in the query, so the sort on timestamp would not be supported because action is missing. For query (2), it is not optimal because action is not the leading field. Thus it is less effective than the two chosen indexes.

  • ✗

    { timestamp: 1 }

    Why it's wrong here

    A single-field index on timestamp alone can help with time-range queries but does not include action, so query (2) would still need to filter action after scanning the index. It also does not help query (1) because user_id is not indexed, leading to inefficient filtering.

  • ✓

    { action: 1, timestamp: 1 }

    Why this is correct

    This index supports query (2) by allowing an equality match on action and a range on timestamp. The index order (action then timestamp) enables efficient filtering and can also support sorting if needed. It is optimal for queries that filter on action and a timestamp range.

About these practice questions

This C100DBA question is part of Courseiva's 222-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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official MongoDB exam blueprint

This C100DBA practice question is part of Courseiva's free MongoDB 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 C100DBA exam.