eriq
eriq

Reputation: 1564

Play! Morphia querying within Collection (i.e. Set or List) fields

I have documents with a Set of Long values for their parent document IDs like so:

{..., "parentIDs" : [ 47, 49 ], ...}

In my Entity class this field is defined as:

@Embedded(concreteClass = java.util.TreeSet.class)
@Indexed
public Set<Long> parentIDs = new TreeSet<Long>();

What would be the Morphia query to return all documents with a specific parent ID (for example 47)?

I'm using:

List<Node> nl = Node.find("type", "event").filter("parentIDs", id).asList();

with id being a correct and existing parent document id. But it does not work. What am I missing?

thanks eriq

Upvotes: 0

Views: 1231

Answers (1)

Arne
Arne

Reputation: 1404

I am not really familiar with the find expression and I am not using Play! But I the way I solve this problem should work for you as well. Instead of using filter, use the methods field() and hasThisOne() .

Could be something like this:

Node.find("type","event").field("parentIDs").hasThisOne(id).asList();

Hope this helps

Regards arne

Upvotes: 2

Related Questions