【发布时间】:2016-11-25 01:45:48
【问题描述】:
我在mongo集合上调用findAndUpdate函数来增加一个计数器,我想得到计数器的值以供进一步使用。这是我的代码:
collection.findAndUpdate(
BSONDocument("name" -> "counter"),
BSONDocument("$inc" -> BSONDocument("count" -> 1)),
fetchNewObject = true,
upsert = true
).map{ e =>
println("count = " + e.value.getAs[Int]("count"))
//I want to do something with the count here
}
这不会编译,因为e.value.getAs[Int]("count") 似乎是错误的。
编译错误是:
value getAs is not a member of Option[service.this.collection.BatchCommands.FindAndModifyCommand.pack.Document]
请多多指教,谢谢!
【问题讨论】:
标签: mongodb scala reactivemongo