Reputation: 934
I want to count how many Items are available in the sub-document Recommendations
in the following document.
{
catgoryId: 13,
Recommendations:
{
{ItemId: 135, value= 0.8},
{ItemId: 136, value= 0.7},
....
}
}
}
Upvotes: 0
Views: 64
Reputation: 58
You can use the aggregation method:
db.test.aggregate(
[
{
$project: {
categoryId:1,
count: {$size:"$Recommendations"}
}
}
]);
Upvotes: 1