I have a collection:
public class Message {
@Id
ObjectId id;
String group;
}
I need to count number of messages per each group. Is it possible to avoid iterating through entire collection?
I have a collection:
public class Message {
@Id
ObjectId id;
String group;
}
I need to count number of messages per each group. Is it possible to avoid iterating through entire collection?
The query language in mongo, and thus morphia, doesn't really support that. The aggregation framework does, however, which is the good news. The (almost)n bad news is that morphia doesn't (yet) support aggregations. I actually have support built on a branch but it's dependent on the 2.12 release of the java driver. Here is the issue tracking this feature: https://github.com/mongodb/morphia/issues/449
Here in this working example, MessageEntry stands for Message and linf stands for group: