Chapter 4: Advanced CRUD Operations Quiz 2: $expr solution is incorrect

The question says: “Which of the following statements will find all the companies that have more employees than the year in which they were founded?”

Strictly speaking this is not a valid answer because of the equals ($founded_year == $number_of_employees will be included in the result and it should not).

db.companies.find(
    { "$expr": { "$lt": [ "$founded_year", "$number_of_employees" ] } }
  ).count()

The same happened with another question before.

it will not count the equal ones as long as you use the $lt operator, $lte means less or equal too

4 Likes

Sorry my bad, too tired when I was reading :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.