I have An Order POJO with a list of products as follows:
@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
public class Order {
@Id
@Generated
private String id;
private String label;
private Collection<Product> products;
private OrderStatus orderStatus;
public Order(String label, List<Product> products, OrderStatus orderStatus) {
this(null, label, products, orderStatus);
}
}
I'm trying to use filters on the order document, and I'm using query and criteria to do so. It works just fine for the primitive fields, for example:
query.addCriteria(Criteria.where(orderField).in(valueList));
mongoTemplate.find(query,Order.class);
But now I'm trying to find all the orders containing a product with a given Id. I guess what I'm trying to do is to perform join on the order collection and on the product collection so that a product matches the Id I want to filter by. I know I can to it easily by using mongorepository, but I'm trying to find a way to do so with criteria.
Latter on I want to be able to perform 'and' and 'or' operation on my filters.
So I don't wanna mix mongoRepository with query and criteria filtering implementations.
I want through the criteria java doc and these answer: Spring Data, MongoDB. How to get nested object (non-document) from document's array and tried to to it like this:
query.addCriteria(Criteria.where("products.id").is(((OrderProductExpression) expression).getValueId()));
Any help would be very appriciated