【问题标题】:Springboot with Mongodb Criteria.orOperation doesn't work带有 Mongodb Criteria.or 运算符的 Spring Boot 不起作用
【发布时间】:2017-02-14 07:44:12
【问题描述】:

我正在尝试使用 Spring-Boot 在 MongoDB 中使用 Criteria 创建一个 OR 操作,这是我的代码:

TypedAggregation<Ficha> agg = newAggregation(Ficha.class,    
   // match(Criteria.where("parte.nome").regex(".*"+ query+".*")),
   // match(Criteria.where("parte.nome").regex(".*"+ query+".*").orOperator(Criteria.where("parte.documentos.numero").regex(".*"+ query+".*"))),
   // match(Criteria.where("parte.documentos.numero").regex(".*"+query+".*")),
   group("parte.nome").first("parte.nome").as("nome"),
   project().and("nome").previousOperation().and("nome").as("nome")

如果我取消注释第 1 行,它会起作用(仅在 parte.nome 中搜索)。

如果我取消注释最后一行,它也可以工作(但只在 parte.documentos.numero 中搜索)。

如果我取消注释中间行,它就不起作用。我该如何解决?

【问题讨论】:

    标签: mongodb spring-boot aggregation-framework spring-data-mongodb mongodb-aggregation


    【解决方案1】:

    实现为:

    TypedAggregation<Ficha> agg = newAggregation(Ficha.class,    
       match(new Criteria().orOperator(
            Criteria.where("parte.nome").regex(".*"+ query+".*"),
            Criteria.where("parte.documentos.numero").regex(".*"+ query+".*")
        )),  
       group("parte.nome").first("parte.nome").as("nome"),
       project().and("nome").previousOperation().and("nome").as("nome")
    );
    

    【讨论】:

      猜你喜欢
      • 2020-07-11
      • 2021-07-26
      • 2022-11-15
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多