Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 9

We have a movies collection with the following document structure:



We need to filter those movies where the imdb rating is greater then 7. Which query should we use?

  • A

    db.movies.find( { "imdb.rating": { "$gt": 7 } } )

  • B

    db.movies.find( { imdb.rating: { "$gt": 7 } } )

  • C

    db.movies.find( { "imdb.rating": { "$gte": 7 } } )

  • D

    db.movies.find( { "imdb.rating": { "$lt": 7 } } )

Reveal correct answer

Correct answer: A

A.

In MongoDB, the find() method is used to retrieve documents from a collection based on specified criteria. The query is specified as a document that contains the filtering conditions. In the provided syntax, we are using the dot notation to specify the field to filter (imdb.rating) and the comparison operator $gt (greater than) to compare the value of imdb.rating with the specified threshold of 7.

B.

The field imdb.rating is not enclosed in quotes. In MongoDB queries, fields that contain special characters or start with certain characters, such as . or $, should be enclosed in quotes.

C.

It uses the $gte (greater than or equal to) operator. While this query would also include movies with a rating equal to 7, the question specifically asks for movies with a rating greater than 7.

D.

It uses the $lt (less than) operator, which would retrieve movies with a rating less than 7. This is the opposite of what the question asks for.

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