У меня проблема с фильтрацией данных mongoDB. Вот данные:
{
"name":"Macbook Pro",
"category":"Apple",
"productId":"X90fD0uD8MsBoc4",
"details":{
"rating":"5",
"stocks":"10",
"price":"null",
"tags":[
{
"tags1":"apple",
"tags2":"macbook",
"tags3":null
}
],
"brand":"Apple",
"description":"null",
"picture":[
{
"picture1":"photo1",
"picture2":"photo2",
"picture3":"photo 3",
"picture4":null,
"picture5":null
}
],
"thumbnails":[
{
"thumbnail1":"thumbails1",
"thumbnail2":"thumbails2",
"thumbnail3":null,
"thumbnail4":null,
"thumbnail5":null
}
]
}
}
Теперь, когда я пытаюсь отфильтровать его с помощью этого кода:
final Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(
Criteria.where("name").regex(query, "i").and("details").elemMatch(
Criteria.where("brand").regex(query, "i"))
),
Aggregation.skip(page * pageable.getPageSize()),
Aggregation.limit(pageable.getPageSize())
);
List<Products> filter = mongoTemplate.aggregate(aggregation, "Product", Products.class).getMappedResults();
return new PageImpl<Products>(filter, pageable, filter.size())
В результате получается пустой массив.