Spring MongoRepository分页请求返回不正确的数据
我在Spring MongoRepository上有一个简单的分页请求,但是MongoRepository显然在一些任意的高页面之后开始发送错误的结果。我在这里发帖是想知道我是否遗漏了什么,或者这可能是SpringMongoRepository的一个bug 在我的测试中,我的测试mongo db中有14个元素,下面的分页请求可以正常工作(如果有,则检索数据):Spring MongoRepository分页请求返回不正确的数据,spring,mongodb,pagination,spring-data-mongodb,mongorepository,Spring,Mongodb,Pagination,Spring Data Mongodb,Mongorepository,我在Spring MongoRepository上有一个简单的分页请求,但是MongoRepository显然在一些任意的高页面之后开始发送错误的结果。我在这里发帖是想知道我是否遗漏了什么,或者这可能是SpringMongoRepository的一个bug 在我的测试中,我的测试mongo db中有14个元素,下面的分页请求可以正常工作(如果有,则检索数据): pageSize:10,page#:0到1073741823 但下面的页面请求从我的mongoDB返回了10个实体,这是我不期望的: p
pageSize:10,page#:0到1073741823
但下面的页面请求从我的mongoDB返回了10个实体,这是我不期望的:
pageSize:10,page#:1073741824
断点是页面大小的diff组合的diff。如有需要,可与他人分享
下面是我正在使用的库:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.5.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.5</version>
</dependency>
org.springframework.data
spring数据mongodb
1.5.5.1发布
org.mongodb
mongo java驱动程序
2.12.5
存储库定义:
public interface SomeEntityRepository extends MongoRepository<SomeEntity, Integer> {
}
公共接口SomeEntityRepository扩展了MongoRepository{
}
并按如下方式使用此存储库:
public Page<SomeEntity> getSomeEntitiesByPage(int pageIndex, int paseSize, Map<String, Sort.Direction> sortQuery) {
Pageable pageableRequest = new PageRequest(pageIndex, pageSize);
return someEntityRepository.findAll(pageableRequest);
}
公共页面getSomeEntitiesByPage(int-pageIndex、int-PasseSize、Map-sortQuery){
Pageable pageableRequest=新的PageRequest(pageIndex,pageSize);
返回sometentityrepository.findAll(pageableRequest);
}
这是Spring MongoRepository的一个问题,Jira也已提交申请。MongoRepository正在尝试获取所需的偏移量Pageable.getOffset()
,返回类型为int,当pageNumber*pageSize>Integer.MaxValue时,它被包装为负偏移量,导致检索第一页。在您的示例中,您只有14条记录,但您声称要查询“pageSize:10,page#:0到1073741823”。“1073741823”到底是什么?你能更具体一点吗?@R4J:在这个例子中,第0页和第1页分别返回10个和4个实体。第2页至1073741823页未返回任何内容,即page.hascantent()=false
,如预期。但令人惊讶的是,对于page#1073741824 to Integer.MaxValue,它返回了10个实体,而它不应该返回。哇。。这很有趣。我刚刚在我的SpringDataMongoDB应用程序中尝试了同样的方法,但在第1073741824页或更高的页面上也出现了同样的情况。我猜spring数据会将大于1073741824的任何值的页面重置为0。我肯定会挖掘更多,我会发布我的发现。我刚刚意识到1073741824等于1GB并且=2^30。基于此,有一个上限集合中文档的最大数量限制,即2^32,是我们在此达到的限制的4倍。Jira已经提交,并且证明是图书馆的问题,他们试图通过Pageable.getOffset()获得偏移量
返回类型为int,并被包装为负值。