How does mongodb count the number of subdocuments?

  mongodb, question

As the topic is.
MongoDB can count the number of documents in a collection using the Count method, which belongs to the collection method, but how to count the number of embedded subdocuments? I have checked the official documents and found no suitable method in the aggregation framework. I hope someone can give me some advice.

db.Scores.aggregate([
{$project: {‘cnt’: {$size: ‘$Scores’}}}
])

The following discussion posts are for your reference:
http://forum.foxera.com/mongo …