Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 22

Given a movies collection where each document has the following structure:



Which of the following queries will find all Comedy movies that were made in 2000? (Select two)

  • A

    db.movies.find( { year: 2000 }, { genres: "Comedy" } )

  • B

    db.movies.find( { $and: [ { year: 2000 }, { genres: "Comedy" } ] } )

  • C

    db.movies.find( { $or: [ { year: 2000 }, { genres: "Comedy" } ] } )

  • D

    db.movies.find( { year: 2000, genres: "Comedy" } )

  • E

    db.movies.find( { year: { $eq: 2000 }, genres: { $eq: "Comedy" } } )

Reveal correct answers

Correct answers: B, D

A.

The second parameter of the find() method is for projection (i.e., selecting which fields to include in the result), not for specifying query conditions. The correct way to use the find() method is to include all query conditions in the first parameter.

B.

The $and operator joins query clauses with a logical AND and returns all documents that match the conditions of both clauses.

C.

The $or operator joins query clauses with a logical OR. It returns all documents that satisfy at least one of the conditions, meaning it would return documents that are either made in 2000 or are comedies, not necessarily both.

D.

When you use a comma-separated list of criteria in the find() method, MongoDB will return documents that satisfy all of these criteria. In other words, this operation is equivalent to an AND operation.

E.

While the syntax used is technically valid, it is unnecessarily verbose and more suited for specific conditions or complex queries where operators are needed. The correct answer achieves the same result more concisely using the basic equality comparison.

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