Courseiva
Indexing →easyMultiple Choice

C100DEV Indexing Practice Question

A developer is working with a collection that stores user profiles. The collection has an index on the `email` field. The developer runs a query that uses a regular expression to find all users whose email ends with "@example.com". The query is: `db.users.find({ email: /@example\.com$/ })`. What is the most likely behavior of this query with respect to the index?

⚠ Common exam trap

The trap here is assuming that any regular expression can benefit from an index, but only left-anchored regexes can use an index effectively.

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 will perform a collection scan because the regular expression is not anchored at the beginning.

MongoDB can use an index for regular expression queries only when the regex is anchored at the start of the string (e.g., /^prefix/). A regex that matches a suffix or an arbitrary substring cannot leverage the index's sorted order, so the query performs a full collection scan. The given query, which looks for emails ending with "@example.com", is not left-anchored and therefore cannot use the index efficiently.

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 will use the index but will still need to filter the results in memory.

    Why it's wrong here

    While it's true that some index scans require additional filtering, in this case the index cannot be used at all because the regex is not left-anchored. The index on email is sorted by the entire string, so a suffix match cannot be efficiently located. Thus, the query will not use the index; it will do a full collection scan.

  • ✗

    The query will use the index efficiently because regular expressions can always leverage indexes.

    Why it's wrong here

    Regular expressions can use indexes only when they are anchored to the beginning of the string (e.g., /^pattern/). A regex that matches a suffix like /@example\.com$/ is not anchored at the start, so the index cannot be used to narrow the search. MongoDB would perform a collection scan, making this option incorrect.

  • ✗

    The query will use the index only if the field is a covered index.

    Why it's wrong here

    A covered index means all fields in the query and projection are in the index. However, even a covered index cannot be used for a non-anchored regex because the index cannot efficiently locate the matching documents. The regex must be left-anchored to use the index, regardless of whether the query is covered.

  • ✓

    The query will perform a collection scan because the regular expression is not anchored at the beginning.

    Why this is correct

    For an index on email to be used, the regular expression must be a prefix match (e.g., /^user/). The given regex /@example\.com$/ matches a suffix, so MongoDB cannot use the index to limit the scan. It will examine every document in the collection, which is inefficient for large datasets. This is the correct behavior.

About these practice questions

One of 259 original C100DEV 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

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 C100DEV 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 C100DEV exam.