【问题标题】:Spring Data Mongo - Bring Paginated Data without embedded documentSpring Data Mongo - 带来没有嵌入文档的分页数据
【发布时间】:2020-03-02 10:39:15
【问题描述】:

我浏览了许多链接,例如:Spring Data Mongo: How to return nested object by its field?。我正在使用 Spring Boot v2.2.2.RELEASE + Spring Data Mongo 示例。

我想用分页数据获取所有员工,但我不想带部门。

Page<Employee> findAll(Pageable pageable); 中我需要更改的内容。

{
    "_id" : ObjectId("5e4143762d8c210ff48f1026"),
    "firstName" : "John",
    "lastName" : "Doe",
    .....
    ......
    ......
    .......
    "departments" : [ 
        {
            "departmentName" : "IT Department",
            "departmentCode" : "IT",
            ....
            ....
        }, 
         ....
         ....
    ]
}

【问题讨论】:

    标签: mongodb spring-data-mongodb


    【解决方案1】:

    我可以使用下面的 Spring Data Mongo 查询来做到这一点。

    @Query(value = "{}", fields = "{'departments': 0}")
    Page<Employee> findAll(Pageable pageable);
    

    【讨论】:

      猜你喜欢
      • 2016-05-15
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 2014-01-09
      • 2015-02-19
      • 2018-12-18
      • 2020-10-31
      • 2020-09-08
      相关资源
      最近更新 更多