ElemMatch quiz code not working

I’m entering these two codes for the quiz related to the elemMatch exercise but the result is 0 documents.

Here are the codes:

{results: {$elemMatch: {product: “abc”, score: 7 }}}

and here’s the second code:
{results: {$elemMatch: {“results.product”: “abc”, “results.score”: {$eq: 7} }}}

I’m not sure why these two codes are both giving me 0 documents as a result on compass.

Can anyone please help me.

Thank you.

Hi Muhammad,

Your first query looks like it should be working. I have tested it in my own database, and can confirm that it is working. I can only think of two things that might be going wrong.

  1. Make sure that you are definitely looking in the results database, and the surveys collection of that database, not scores. Also make sure you are looking in the cluster we have been using for class, not the sandbox cluster we made.

  2. Make sure that the "abc" in your query is not using “Smart Quotes”, which look like this: “abc”. So the correct query would be:
    {results: {$elemMatch: {product: "abc", score: 7 }}}
    {results: {$elemMatch: {product: “abc”, score: 7 }}}

Your second query is not valid syntax, as results. before product and score is redundant, and will not work.

I hope this helps!