Help with syntax

In the results database you will find two collections: surveys and scores. Documents in the results.surveys collection have the following schema.

{_id: ObjectId(“5964e8e5f0df64e7bc2d7373”),
results: [{product: “abc”, score: 10}, {product: “xyz”, score: 9}]}
The field called results that has an array as its value. This array contains survey results for products and lists the product name and the survey score for each product.

How many documents in the results.surveys collection contain a score of 7 for the product, “abc”?

Question:
what is the syntax to find the answer please?
I am using the following but I do not get the correct answer
Thank you

{
$and:
[
{“results.product”: {$eq: “abc”}},
{“results.score”: {$eq: 7}}
]
}

Look at the $elemMatch operator

1 Like