ReactiveMongo与光标聚合

时间:2016-01-12 22:02:10

标签: mongodb scala aggregation-framework reactivemongo

我尝试使用游标执行ReactiveMongo aggregate调用,以避免结果大小restrictions

def sumPerUser(appId: String, date: DateTime): Future[Seq[UserImpressionSums]] = {
import collection.BatchCommands.AggregationFramework._

collection.aggregate(
  Match(BSONDocument(APP_ID -> appId, DATE_CREATED -> BSONDocument("$gte" -> BSONDateTime(date.getMillis)))),
  List(Project(BSONDocument(USER -> 1, DATE_CREATED -> 1, IP -> 1, CAMPAIGN_ID -> 1, "imp" -> BSONDocument("$literal" -> 1) )),
    Group(BSONDocument(USER -> "$user", IP -> "$ip", CAMPAIGN_ID -> "$campaign_id"))
    ("totalImps" -> SumField("imp"), DATE_CREATED -> First(DATE_CREATED)),
    Sort(Ascending(DATE_CREATED))
  ), false, true, Some(Cursor(100)))

  .map(_.result[UserImpressionSums])
}}

代码编译正确,但在执行时抛出异常:

reactivemongo.api.commands.bson.DefaultBSONCommandError: CommandError[code=14, errmsg=cursor field must be missing or an object, doc: {
  ok: BSONDouble(0.0),
  errmsg: "cursor field must be missing or an object",
  code: BSONInteger(14)
}]

为什么会发生这种情况的任何想法?

0 个答案:

没有答案