[Solution] Challenge Problem

I really didn’t understand the result that differentiates the {results: { gt: 70, lt: 80}} filter and the {results: { elemMatch: { gte: 70, $ lt: 80}}} filter. when the result of this second filter has values ​​of the type

{"_id": “5964e8e5f0df64e7bc2d738b”, “results”: [78,92,87]}


@HARRY_76387 I don’t quite understand your post but is this an answer to one of the labs? It’s not recommended to post solutions to labs.

Hi @HARRY_76387,

The first query matches documents that contain an array field where the elements in the array matches all the specified query criteria. Let’s understand this with an example.

If we have a document like this :

{"name" : "Jack", "results": [20,90,180] }

The first query will match this document because, there is at least one element in the array which satisfies all the criterion. 20 is less than 80 and 90 is greater than 70.

However, what you want is at least one element in the array field which matches all the specified query criteria and your second query does exactly the same.

Hope it helps!

If you have any other query, please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Rajan
Curriculum Support Engineer