users
让我们考虑一下我有一个具有该age
属性的集合。现在我想计算集合中的所有文档,users
或者只计算与age
属性匹配的文档。所以,我做了以下事情:
def count(age: Option[Int] = None) = {
if (age.isEmpty) roles.count()
else users.count(Json.obj("age" -> age))
}
问题是会users.count(Json.obj("age" -> age))
引发编译错误,因为count
响应式 mongo 提供的方法需要 type Option[pack.Document]
。知道如何解决这个问题吗?
如果这很重要,我正在使用 Reactive Mongo 版本 0.11.11。