Mongodb 使用JsObject在Reactivemongo中计数

Mongodb 使用JsObject在Reactivemongo中计数,mongodb,scala,playframework-2.1,reactivemongo,Mongodb,Scala,Playframework 2.1,Reactivemongo,我试图在查询上实现Count,但我遇到了问题,因为我没有 使用BSONDocument,但使用JsObject对象 我应该将我的JsObject翻译成BSONDocument还是有更好的方法? 在ReactiveMongo 0.9中,您将如何执行此操作?翻译示例: 服务: def countSentMailForVenue(currentId: Long, from: DateTime, to: DateTime) : Future[Int] = { val query = Jso

我试图在查询上实现Count,但我遇到了问题,因为我没有 使用BSONDocument,但使用JsObject对象

我应该将我的JsObject翻译成BSONDocument还是有更好的方法? 在ReactiveMongo 0.9中,您将如何执行此操作?

翻译示例:

服务:

  def countSentMailForVenue(currentId: Long, from: DateTime, to: DateTime) : Future[Int] = {
    val query = Json.obj("venueInfo.currentId" -> venueId, "origin" -> Origin.EMAIL_INVITE, "updated" -> Json.obj("$gte" -> from.getMillis, "$lt" -> to.getMillis))
    count(BSONFormats.toBSON(query).get.asInstanceOf[BSONDocument])
  }
/**
   * Currently Count() only supports BSONDocument.
   */
  def count(query: BSONDocument) : Future[Int] = {
    Logger.debug(s"Counting documents: "+BSONFormats.toJSON(query))
    val futureCount = collection.db.command(
      Count(
        collection.name,
        Some(query)
      )
    )
    futureCount
  }
而在Dao中:

  def countSentMailForVenue(currentId: Long, from: DateTime, to: DateTime) : Future[Int] = {
    val query = Json.obj("venueInfo.currentId" -> venueId, "origin" -> Origin.EMAIL_INVITE, "updated" -> Json.obj("$gte" -> from.getMillis, "$lt" -> to.getMillis))
    count(BSONFormats.toBSON(query).get.asInstanceOf[BSONDocument])
  }
/**
   * Currently Count() only supports BSONDocument.
   */
  def count(query: BSONDocument) : Future[Int] = {
    Logger.debug(s"Counting documents: "+BSONFormats.toJSON(query))
    val futureCount = collection.db.command(
      Count(
        collection.name,
        Some(query)
      )
    )
    futureCount
  }