Skip to content

Commit 97f5062

Browse files
committed
refactor: limit for pagination is an int in official mongodb driver
1 parent 1434f75 commit 97f5062

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "mongodb-driver",
33
"organization" : "dev.mongocamp",
4-
"version" : "3.0.10.snapshot",
4+
"version" : "3.0.10",
55
"author" : "[email protected]",
66
"license" : "Apache-2.0",
77
"type" : "module",

src/main/scala/dev/mongocamp/driver/mongodb/operation/Search.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ abstract class Search[A]()(implicit ct: ClassTag[A], decoder: Decoder[A]) extend
2020

2121
def find(filter: Bson = Document(), sort: Bson = Document(), projection: Bson = Document(), limit: Int = 0, skip: Int = 0): Observable[A] = {
2222
val findObservable = {
23+
val internalLimit = if (limit == Int.MaxValue) limit - 1 else limit
2324
if (limit > 0) {
24-
coll.find(filter).sort(sort).projection(projection).limit(limit).skip(skip)
25+
coll.find(filter).sort(sort).projection(projection).limit(internalLimit).skip(skip)
2526
}
2627
else {
2728
coll.find(filter).sort(sort).projection(projection).skip(skip)

src/main/scala/dev/mongocamp/driver/mongodb/pagination/MongoPaginatedAggregation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ case class MongoPaginatedAggregation[A <: Any](
1919
private val AggregationKeyData = "data"
2020
private val AggregationKeyMetaDataTotal = "total"
2121

22-
def paginate(page: Long, rows: Long): PaginationResult[Document] = {
22+
def paginate(page: Int, rows: Int): PaginationResult[Document] = {
2323
if (rows <= 0) {
2424
throw MongoCampPaginationException("rows per page must be greater then 0.")
2525
}

src/main/scala/dev/mongocamp/driver/mongodb/pagination/MongoPaginatedFilter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.mongodb.scala.bson.conversions.Bson
77
case class MongoPaginatedFilter[A <: Any](dao: MongoDAO[A], filter: Bson = Map(), sort: Bson = Map(), projection: Bson = Map(), maxWait: Int = DefaultMaxWait)
88
extends MongoPagination[A] {
99

10-
def paginate(page: Long, rows: Long): PaginationResult[A] = {
10+
def paginate(page: Int, rows: Int): PaginationResult[A] = {
1111
val count = countResult
1212
if (rows <= 0) {
1313
throw MongoCampPaginationException("rows per page must be greater then 0.")
@@ -17,7 +17,7 @@ case class MongoPaginatedFilter[A <: Any](dao: MongoDAO[A], filter: Bson = Map()
1717
}
1818
val allPages = Math.ceil(count.toDouble / rows).toInt
1919
val skip = (page - 1) * rows
20-
val responseList = dao.find(filter, sort, projection, rows.toInt, skip.toInt).resultList(maxWait)
20+
val responseList = dao.find(filter, sort, projection, rows, skip).resultList(maxWait)
2121
PaginationResult(responseList, PaginationInfo(count, rows, page, allPages))
2222
}
2323

src/main/scala/dev/mongocamp/driver/mongodb/pagination/MongoPagination.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dev.mongocamp.driver.mongodb.pagination
33
import dev.mongocamp.driver.mongodb.database.ConfigHelper
44

55
trait MongoPagination[A <: Any] extends ConfigHelper {
6-
def paginate(page: Long, rows: Long): PaginationResult[A]
6+
def paginate(page: Int, rows: Int): PaginationResult[A]
77
def countResult: Long
88

99
def foreach(a: A => Unit): Unit = {

src/test/scala/dev/mongocamp/driver/mongodb/pagination/PaginationFilterSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PaginationFilterSuite extends BasePersonSuite with MongoImplicits {
1010
test("search with rows Long MaxValue") {
1111
val personCollectionCount = PersonDAO.count().result().toInt
1212
val pagination = MongoPaginatedFilter(PersonDAO)
13-
val page = pagination.paginate(1, Long.MaxValue)
13+
val page = pagination.paginate(1, Int.MaxValue)
1414
assertEquals(page.paginationInfo.allCount, personCollectionCount.toLong)
1515
assertEquals(page.databaseObjects.size, personCollectionCount)
1616
}

0 commit comments

Comments
 (0)