Chapter 3: Admin Backend Ticket: User Report - mostActiveCommenters

How do we get List< Critic > mostActive from :-

AggregateIterable< Comment >itr = commentCollection.aggregate(pipe);

Even if i iterate the AggregateIterable i will not get the count property from it because comment object does not have the count property.

What is the way to solve this ?

You may want to use a group -> sort -> limit pipeline to solve this ticket. The count field is created while grouping stage.

Yes the pipeline is working. Cross checked in the compass .

So u mean to say in AggregateIterable < Comment > we get count ?

Comment class does not have count property and AggregateIterable will be of type Comment.
I hope i am making sense.

You can use the aggregate method with the next parameters:
aggregate​(List<? extends Bson> pipeline, Class resultClass )
In this ticket, we could pass in Critic.class as the second parameter, so that AggregateIterable < Comment > becomes < Critic >. Just make sure to only provide “_id” and “count” fields.

Check this comment by fsvargas if my comment is not clear to you.


Great, it resolved the my issue.
I should have checked the implementation of AggregateIterable.

Thanks a lot.

I have a doubt in this as well as create and update comment, receiving unable to update message.If you have completed the chapter 2 can you please let me know.