有人能帮助我吗?我试图在springboot中使用聚合(mongodb)我有这些类:
@Document
public class Ficha {
//FIXME adicionar validacao
@Id
private String id;
private Parte parte;
...}
public class Parte {
private String nome;
private List<Documento> documentos;
...}
public class Documento {
private String tipo;
private String orgaoExpedidor;
private String numero;
...}
所以我需要返回这个课程:
public class SugestaoParte {
private String nome;
private String documento;
}
首先我尝试基本的:
Aggregation agg = newAggregation(
match(Criteria.where("parte.nome").regex(".*"+ query+".*")),
group("parte.nome").first("parte.nome").as("nome"),
project("parte.nome")
);
AggregationResults<SugestaoParte> results = mongoTemplate.aggregate(agg, Ficha.class, SugestaoParte.class);
return results.getMappedResults();
只按名称分组,但是只有将_id属性放在我的类SugestaoParte中,我的返回才有效,如何将nome.parte设置为nome字段?
之后我需要返回,比如tis:
name =&#34; nome.parte&#34; documento =&#34; nome.parte.documento [1] + nome.parte.documento [2] .....&#34;
TKS