【问题标题】:SpringData MongoDB Query on nested object and list objectSpringData MongoDB查询嵌套对象和列表对象
【发布时间】:2019-10-02 14:49:19
【问题描述】:

我想通过jobcodecategorycode 列表查找Type 文档,我尝试了以下查询,但没有成功

@Document
public class Type {
    @Id
    private String id;
    @DBRef
    private Job job;
    @DBRef
    private List<Category> categories;
}

public class Job {
    @Id
    private String id;
    private String code;
}

public class Category {
    @Id
    private String id;
    private String code;
}

public interface TypeRepository extends MongoRepository<Type, String> {
    @Query("{ 'job.code': ?0, 'category.code': { $in: ?1 }}")
    Type findByJobAndCategoriesCode(String codeJob, List<String> codeCategories);
}

【问题讨论】:

    标签: java spring-data spring-data-mongodb


    【解决方案1】:

    试试这个

    public interface TypeRepository extends MongoRepository<Type, String> {
    
        Type findOneByJobCodeAndCategoriesCodeIn(String codeJob, List<String> codeCategories);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      相关资源
      最近更新 更多