在使用Salat的组合键上有职位,但是缺少关于确保索引(来自mongo-db控制台,db.collection.ensureIndex({someField : 1}))的信息。通过Salat源代码,我没有看到将字段标记为需要索引的注释,有什么方法可以这样做吗?
发布于 2014-01-12 08:13:26
直接从DAO对象内部访问MongoCollection是可能的(请参阅:这个论坛帖子)。例如:
object AlphaDAO extends SalatDAO[Alpha, Int](collection = MongoConnection()("test_db")("test_coll")) {
val beta = new ChildCollection[Beta, Int](
collection = MongoConnection()("test_db")("test_col1_subcol1"),
parentIdField = "alphaId") {}
import com.mongodb.casbah.Imports._
collection.ensureIndex(DBObject("some.field" -> 1, "anotherField" -> 1))
beta.collection.ensureIndex(DBObject("some.field" -> 1, "anotherField" -> 1))
}https://stackoverflow.com/questions/21072637
复制相似问题