ReactiveMongo查询无法分页

时间:2015-11-16 20:41:35

标签: mongodb scala reactivemongo

在让ReactiveMongo =IF(E4 - D4 >= 3,C4 + 3,"IF(E4 - D4 <= -2, C4 - 2, IF(E4 - D4 > 0 And E4 - D4 < 3, C4 + E4 - D4, IF(E4 - D4 > -2 And E4 - D4 < 0, G4 = C4 + E4 - D4, C4)))") 对我的查询进行分页时遇到一些问题。行为是它返回所有结果,而不是逐页结果。

这是我的疑问:

0.11

请注意,分页从def listConvos(userId: String, page: Int, pageSize: Int) = { val query = BSONDocument("userId" -> userId) val sort = BSONDocument("lastActivity" -> -1) val skipN = (page-1) * pageSize val queryOptions = new QueryOpts(skipN = skipN, batchSizeN = pageSize, flagsN = 0) collection.find(query).options(queryOptions).sort(sort).cursor[ConvoDesc](ReadPreference.primaryPreferred).collect[List]() 开始。使用IntelliJ调试器,上述变量的值为:

1

我还可以确认我在userId = "29aosidfj43903p" query = BSONDocument(<non-empty>) sort = BSONDocument(<non-empty>) queryOptions = QueryOpts(10,10,0) page = 2 pageSize = 10 userId字段上设置了复合索引。谢谢你的帮助!

1 个答案:

答案 0 :(得分:3)

解决方案还包括collect方法中的页面大小,如下所示:

collection.find(query).options(queryOptions).sort(sort).cursor[ConvoDesc](ReadPreference.primaryPreferred).collect[List](pageSize)