Difference in output with $elemMatch

Hi All,

What is the difference between these two commands: I just did a count of number of writers with and without $elemMatch and i get the output diffrently.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate( [ { $match: { writers: { $exists: true } } } ] ).itcount()
41572
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate( [ { $match: { writers: { $elemMatch: { $exists: true } } } } ] ).itcount()
41500
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

Thanks in advance.

Sorry, I have got to thing actually, $elemMatch ignores the null array element and calculated the count.
I dont have delete access to delete the post. But, i thought to update so that if someone reads it will be like an add on.

@ Suresh_58788

Glad you got it, and we’ll leave this here to help others if they have the same or a similar problem. Good luck.