Quiz at the end of chapter

Hi,

I’m curious if I had choose the right query for the quiz at the end of the chapter. I found 1020 documents, I am right?
How many did you find?

I think I did the same thing initially, while constructing my solution because I also got 1020 documents at that step. Assuming that you did what I did, if you look at the 6th document, none of the scores satisfy the criteria.

My completed query yielded 744. Spot checking the results seem to confirm this, but it would be nice to have confirmation! If no one can confirm, I guess I’ll have to start looking at all 744 documents.

2 Likes

Hi Federico_93936,

The correct answer is 744.

Kanika

3 Likes

I got 1020 as well

i used
db.scores.find({$and: [{results: {$gte: 70}, results: {$lt:80}}]}).count()

Hi Hemanthpradeep,

Please review my post.

Let me know if it helps!

Kanika

1 Like

Yes, the answer is 744. This query will be solved by using the $elemMatch Operator as follows:
{“results”: {$elemMatch: {$gte:70, $lt:80}}}. Am I right @Kanika?

1 Like

Yes @Salabh_92484 :slight_smile:

Kanika

What would be the difference between:

  1. db.scores.find( { “results”: { “$elemMatch”: { “$gte”: 70, “$lt”: 80 } } } )

  2. db.scores.find( { “results”: { “$gte”: 70, “$lt”: 80 } } )

@Kanika

Hi @Yago_83503,

Please review my post:

If still you have questions, feel free to post here.

Kanika

1 Like