Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 14

Given the following example document from an artists collection:



And the following index:



How MongoDB will handle the query below?



  • A

    MongoDB will need to perform a full collection scan.

  • B

    This query is incorrect.

  • C

    As an index scan.

  • D

    MongoDB will need to use the $regex operator for the query.

Reveal correct answer

Correct answer: C

A.

MongoDB does not need to perform a collection scan because there is an index on the "last_name" field, which allows for more efficient searching.

B.

The query is valid, and it searches for documents in the "artists" collection where the "last_name" field matches a pattern starting with the letter "O".

C.

The query is searching for documents in the "artists" collection where the "last_name" field matches a pattern that starts with the letter "O". Since an index exists on the "last_name" field, MongoDB can utilize the index to efficiently search for documents that match the query pattern. It will perform an index scan to find and return the matching documents.

D.

The $regex operator is typically used when you want to perform more complex pattern matching using regular expressions. It allows you to specify a regular expression as a string and apply it to a specific field in the query. However, in the given query, the regular expression pattern is directly specified in the query object without the need for the $regex operator.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need