1

有人能帮我吗?我试图在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:

名称 = "nome.parte" 文档 = "nome.parte.documento[1] + nome.parte.documento[2]....."

tks

4

0 回答 0