nerdexam
MongoDB

C100DBA · Question #21

Which of the following commands will return all the posts with number of likes greater than 100 and less than 200, both inclusive?

The correct answer is A. db.posts.find({ likes : { $gte : 100 , $lte : 200 } } );. Option A is correct because $gte (greater than or equal) and $lte (less than or equal) together form an inclusive range - capturing posts where likes is exactly 100, exactly 200, or any value in between. Option B fails because $gt excludes 100 itself, making the lower bound exclu

MongoDB Fundamentals

Question

Which of the following commands will return all the posts with number of likes greater than 100 and less than 200, both inclusive?

Options

  • Adb.posts.find({ likes : { $gte : 100 , $lte : 200 } } );
  • Bdb.posts.find({ likes : { $gt : 100 , $lte : 200 } } );
  • Cdb.posts.find({ likes : { $gte : 100, $lt : 200 } } );
  • Ddb.posts.find({ likes : { $gt : 100, $lt : 200 > > );

How the community answered

(34 responses)
  • A
    88% (30)
  • B
    3% (1)
  • C
    3% (1)
  • D
    6% (2)

Explanation

Option A is correct because $gte (greater than or equal) and $lte (less than or equal) together form an inclusive range - capturing posts where likes is exactly 100, exactly 200, or any value in between. Option B fails because $gt excludes 100 itself, making the lower bound exclusive. Option C fails similarly because $lt excludes 200, making the upper bound exclusive. Option D uses $gt and $lt, making both bounds exclusive, and also has a syntax error (> > instead of }}).

Memory tip: The e in $gte/$lte stands for "equal" - if the question says "inclusive," you need the e on both ends.

Topics

#$gte#$lte#range query#comparison operators

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice