2

我使用 play Reactivemongo 插件和 Reactivemongo 一起工作。

def list(ps: Int = pageSize, page: Int = 1, sortBy: String = "_id", order: Int = 1,   filterKey: String = "", filter: String = "") = Action.async { implicit request =>
  val builder = filterKey.length > 0 && filter.length > 0 match {
    case true => collection.find(Json.obj(filterKey -> filter))
    case false => collection.genericQueryBuilder
  }

  val cursor:Cursor[JsObject] = builder
    .sort(Json.obj(sortBy -> order))
    .options(QueryOpts(skipN = (page - 1) * ps, batchSizeN = 10)).cursor[JsObject]

  val futurePersonsList = cursor.collect[List]()

  val futurePersonsJsonArray = futurePersonsList.map { list =>
    Json.arr(list)
  }

  futurePersonsJsonArray.map { list =>
  //Logger.debug(list(0).)
    Ok(list(0)).as(JSON)
 }
}

batchSizeNQueryOpts我以为它会收回 10 件物品,但事实并非如此。
最后我更改cursor.collect[List]()cursor.collect[List](10),它可以工作。我的问题是 batchSizeN 用于 mongodb 命令的find().limit()方式是否相同?和 和
有什么区别?QueryOpts.batchSizeNcursor.collect[List](10)

4

1 回答 1

1

批量大小是这样的: http: //docs.mongodb.org/manual/reference/method/cursor.batchSize/

限制是这样的: http: //docs.mongodb.org/manual/reference/method/cursor.limit/

于 2014-07-08T09:07:43.337 回答