MongoDB find match in array of objects || MongoDB where condition with array of objects | $elemMatch or dot notation match

In MongoDB, $elemMatch and dot notation are used to find the match in the array of objects. But both have some difference.
Let me explain this with an example. Let say we have a document like:

Now let me find the class name whose students has scored greater than 86.

If using the dot notation then here is the example:

The result will be :

Now If I find the class name whose students has scored greater than 86 and their section is A by using dot notation.

The result will be:

Hence if we are using dot notation, Any condition match in students array, like score or section will be returning document.



But what if we wanted to match every condition?  The answer is: We use $elemMatch for that. ...  Read More

Share This: