Ticket: User Report

public List mostActiveCommenters() {
List 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.
List pipeline = new LinkedList<>();
pipeline.addAll(Arrays.asList(new Document("$group",
new Document("_id",
new Document(“email”, “$email”))
.append(“count”,
new Document("$sum", 1L))),
new Document("$sort",
new Document(“count”, -1L)),
new Document("$limit", 20L)));
commentCollection.aggregate(pipeline,Critic.class).into(mostActive);
return mostActive;
}

This is my implementation. I am getting this error while running junit test “Failed to decode ‘Critic’. Decoding ‘_id’ errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.”

@kanikasingla please help me with this

pipeline.addAll(Arrays.asList(new Document("$group",
new Document("_id", “$email”)
.append(“count”,
new Document("$sum", 1L))),
new Document("$sort",
new Document(“count”, -1L)),
new Document("$limit", 20L)));

solved :grinning:

1 Like

That is great :slight_smile: Good luck!