I am getting this error
org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a ‘Comment’ failed with the following exception:Failed to decode ‘Comment’. Decoding ‘_id’ errored with: readObjectId can only be called when CurrentBSONType is OBJECT_ID, not when CurrentBSONType is STRING.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
The pipeline code is this
BsonField sum1 = Accumulators.sum("count", 1);
// adding both group _id and accumulators
Bson groupStage = Aggregates.group("$email", sum1);
Bson sortStage = Aggregates.sort(Sorts.descending("count"));
Bson limitStage = Aggregates.limit(20);
List<Bson> pipeline = new ArrayList<>();
pipeline.add(groupStage);
pipeline.add(sortStage);
pipeline.add(limitStage);
List<Comment> results = new ArrayList<>();
commentCollection.aggregate(pipeline).into(results);
I did check the thread here Ticket: User Report but it didn’t help