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 フィールドに設定するにはどうすればよいですか??

この後、次のように返す必要があります。

name = "nome.parte" documento = "nome.parte.documento[1] + nome.parte.documento[2]....."

tks

4

0 に答える 0