Hello, can enyone help me how to use MongoTemplate to find documents by embeded object value?
I have a classes:
@Document("items")
public class GroceryItem {
@Id
private String id;
private String name;
private Integer quantity;
private String category;
private List<Product> products;
...
Embeded class:
public class Product {
private String name;
private List<Level> levels;
...
and
public class Level {
private String name;
...
How can I find document by embeded product “name” or level “name” field?
It is not working with query:
Query query = new Query(Criteria.where("name").is(name)
.and("products.name").is(productName));
With @Query annotation it works fine:
@Query(value = "{ 'quantity' : ?0, 'products.name' : ?1, 'products.levels.name' : ?2 }")
Stream<GroceryItem> findByQuantityProdNameLevelName(int quantity, String prodName, String level);
Thanks.