У меня есть следующий документ
[ {
"pageName": "Content_2",
"domain": "bingo.com",
"locale": "en-us",
"contents": [
{
"contentName": "Template_2",
"fields": [
{
"title": "Company Name"
},
{
"title": "Designation"
}
]
}
]
},
{
"version": 2,
"pageName": "Content_3",
"domain": "bingo.com",
"locale": "en-in",
"contents": [
{
"contentName": "Template_2",
"fields": [
{
"title": "Company Name"
},
{
"title": "Designation"
}
]
}
]
}]
Я фильтрую данные на основе домена, локали и имени содержимого. До этого момента все работает нормально. Теперь внутри массива полей я хочу показать только те поля, заголовок которых соответствует определенному значению. Я не могу понять, как это сделать с помощью операции агрегации. Я пробовал ниже фрагмент:
Aggregation aggregation = newAggregation(
match(
where("domain").is(domain)
.and("contents.contentName").is(templateName)
.and("locale").in(criteria.getLocales())),
project().and(new AggregationExpression() {
@Override
public Document toDocument(AggregationOperationContext aggregationOperationContext) {
DBObject filterExpression = new BasicDBObject();
filterExpression.put("input", "$contents.fields");
filterExpression.put("as", "field");
filterExpression.put("cond",
new BasicDBObject("$eq", Arrays.<Object>asList("$$field.title", "Company Name")));
return new Document("$filter", filterExpression);
}
}).as("field"));
AggregationResults<MyClass> list = mongoOperations.aggregate(aggregation, MyClass.class,
MyClass.class);
Он возвращает все атрибуты как null. Пожалуйста, направляйте. Я новичок в MongoDB. Заранее спасибо;