Clarification about Critic class [Solved]

The Critic class is built with two attributes: id and numComments.
What is id made of? Is it a user’s email or _id?

This is related to Chapter 3 -> Ticket: User Report.

Hi @Prasad_45636

If you look at the top of the class, you can see that it’s associated to _id using a Java Annotation. The JsonProperty annotation instructs the Jackson ObjectMapper to map the JSON property name to the annotated Java field’s name, in this case _id.

  public class Critic {
  private String id;

Hope this explains it!

Thanks for the reply.

   * Ticket: User Report - produce a list of users that comment the most in the website. 
   * Query the `comments` collection and group the users by number of comments.
   * The list is limited to up most 20 commenter.
   * @return List {@link Critic} objects.
  public List<Critic> mostActiveCommenters() {

      List<Critic> mostActive = new ArrayList<>();

      // // TODO> Ticket: User Report - execute a command that returns the
      // // list of 20 users, group by number of comments. Don't forget,
      // // this report is expected to be produced with an high durability
      // // guarantee for the returned documents. Once a commenter is in the
      // // top 20 of users, they become a Critic, so mostActive is composed of
      // // Critic objects.

      return mostActive;

So, my query is to join the comments and user collections to arrive at a list of 20 users (with highest comments). Each user and the number of comments are the top critics. The Critic class stores these users (User collection’s _id) and the number of comments.

From the tests I figured that the Critic id field is the email of the user. So, the query is built using the comment collection (this has the user’s email). This got me thru the test.

1 Like