Aggregation query to get size of list

11 views
Skip to first unread message

Vaishnavi Manjunath

unread,
Oct 12, 2017, 4:18:27 AM10/12/17
to Morphia
Hi, 
    I am trying to count the number of elements in a list of each document in a collection, similar to below example. (https://docs.mongodb.com/manual/reference/operator/aggregation/size/#exp._S_size)

I am unable to arrive at an equivalent morphia query to achieve the same.
Any help in this regard would be greatly appreciated.

Thanks,

db.inventory.aggregate(
   [
      {
         $project: {
            item: 1,
            numberOfColors: { $size: "$colors" }
         }
      }
   ]
)
Reply all
Reply to author
Forward
0 new messages