Search code examples
mongodbprojectionmorphia

Filter Subarrays return Morphia


I have a problem such like this:

@Entity
public class Event {

@Embedded
List<Edition> editions;
}

@Entity
public class Edition {

private A a;
private B b

private Date schedule

@Embedded
List<C> cs;
}



@Entity
public class C {
  ...
}

What I am trying to do is search filtering the list of Editions in Event by a schedule however without values os Cs

Something like

List<Event> events = this.basicDAO.find(query.filter("editions.schedule >", startsIn.toDate()).retrievedFields(true, 
                "editions.a",
                "editions.b",
                "editions.schedule",
                "editions.$")).asList();

However this does not works, I still get the value of Cs. I try mix retrieveFields true and false put editions.c in false clause however it is not allowed.

Is there a way to filter collections using projection or projections always return the full document?


Solution

  • That can be achieved using aggregation $project, and now Morphia supports aggregation (since 0.110). Here you have some examples about aggregation and group&projection.