0

给出以下代码:

 def findDistinctTypeValues(): Set[String] = {
    //cast all instances from Any to String
    val coll = dao.collection.distinct("hybridType") map (_.asInstanceOf[String])
    coll.toSet
  }

如何以一种通用的方式做到这一点?(在这种情况下,我预先知道“混合类型”是一个字符串。我认为必须有一个通用的方法。

提前致谢

4

1 回答 1

1

Salat author here.

Look at SalatDAO#primitiveProjections -

MyDAO.primitiveProjections[String](/* some query or DBObject.empty for all */, "hybridType")

See the section on projections at SalatDAO wiki page

于 2013-09-13T15:16:52.890 回答