hasThisElement
expects an object in the parameter, so you couldn't use a String "fooType" or “bar”.
Assume that you have the following classes for this collection:
class Clients {
String id;
String name;
List<Product> products = new ArrayList<Product>();
String status;
}
class Product {
String fooType;
....
}
To use $elemMatch
, you would need to create an object for the filter on products
as below, and use this filter object in hasThisElement()
:
Product filterProduct = new Product();
filterProduct.fooType = "bar";
Query q = ds.createQuery(Clients.class).field("products").hasThisElement(filterProduct);