我尝试使用游标执行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)
}]
为什么会发生这种情况的任何想法?