When you use a single collection to contain an entire type hierarchy, then use this trait to make sure that type hints are appended to find, count and update queries.
Base DAO class.
Base DAO class.
Where WriteConcern
is not specified as a parameter on an operation which modifies or removes documents from the
collection, then the default write concern of the collection is assumed.
class to be persisted
_id type
Play framework style model companion
Play framework style model companion
package model import salat.annotations._ import com.mongodb.casbah.Imports._ import salat.dao.{ SalatDAO, ModelCompanion } object MyModel extends ModelCompanion[MyModel, ObjectId] { val collection = MongoConnection()("my_db")("my_model_coll") val dao = new SalatDAO[MyModel, ObjectId](collection = collection) {} } case class MyModel(@Key("_id") id: ObjectId, x: String, y: Int, z: List[Double])
type of object to be serialized
type of object id to be serialized
Sample DAO implementation.
Sample DAO implementation.
class to be persisted
_id type
Unfortunately, MongoCursorBase is typed to DBObject, but....
Unfortunately, MongoCursorBase is typed to DBObject, but.... Ripped off from casbah-mapper. https://github.com/maxaf/casbah-mapper/blob/master/src/main/scala/mapper/MappedCollection.scala
When you use a single collection to contain an entire type hierarchy, then use this trait to make sure that type hints are appended to find, count and update queries. (Please note you need to make sure your indexes on this shared collection take your type hint fields into account!)
In addition, when you use the concrete subclass DAO to insert, update and save objects, a type hint will be appended to the serialized object.