我的文档结构如
{
"users":[
{
"email":"user@company.com"
"messages":[
{
"id":"1",
"text":"A",
"from":"Jessy",
"isDeleted":"false"
},{
"id":"2",
"text":"B",
"from":"Jessy",
"isDeleted":"false"
},{
"id":"3",
"text":"C",
"from":"Alan",
"isDeleted":"false"
},{
"id":"4",
"text":"D",
"from":"Amy",
"isDeleted":"true"
},{
"id":"5",
"text":"E",
"from":"Amy",
"isDeleted":"false"
}
]
}
]
}
我想使用或& amp;查询子文档和操作。所以我的查询可以如下。
从用户集合中选择所有那些来自“Amy”并且文本为“E”或其他标准的消息。
我对Spring数据支持的聚合框架有一个了解
AggregationOperation match =Aggregation.match(Criteria.where("from").is("Amy").and("text").is("E"));
AggregationOperation unwind = Aggregation.unwind("messages");
Aggregation aggregation = Aggregation.newAggregation(match);
AggregationResults<User> result = this.mongoTemplate.aggregate(aggregation, "users", User.class);
但我的问题是我想动态填充Criteria,就像Criteria在客户端,他或她可以将任何查询传递给数据库,我会将该查询解析为Criteria。任何帮助将不胜感激。