Query projection on a @Reference field

48 views
Skip to first unread message

Franklin Dattein

unread,
Oct 20, 2015, 10:06:06 PM10/20/15
to Morphia
Hi all,

is it possible to define a projection on @Reference objects?

This is what I have got:

@Entity
public class A {
   @Reference(lazy=true)
private Collection<B> collectionOfB;
   ...

public class B  {

   private String name;
   private String desc;

And I want to retrieve only a sub-set of fields from B, so my DAO looks like this:

return createQuery()
.field("_my_id").equal(myId)
.retrievedFields(true,
"collectionOfB.name"
)
.asList();


However, it doesn't work. Am I am missing something?

Thanks,
Franklin Dattein

Justin Lee

unread,
Oct 21, 2015, 8:22:00 AM10/21/15
to mor...@googlegroups.com
in order to do that, you'd have to do a join which mongodb does not support.  you'll have to do two separate queries to get what you want.

--------------------------------

name     : "Justin Lee", 
  title    : "Software Engineer",
  twitter  : "@evanchooly",
  web      : [ "mongodb.com", "antwerkz.com" ],
  location : "New York, NY" }

--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages