Hello, I am trying to convert a project from Casbah 2.8 to the new Mongo 1.0.0 driver.
The way the project is set up, we have case classes defined for the different Document types in our Mongo database. What we had for the Casbah implementation was a Format class that would translate between the MongoDBObject and our case class object. The main reason is to convert from database _ naming to standard Scala camelCase naming.
In the new Mongo 1.0.0 driver, it looks like the Translation logic to go from a String to a BsonString exists, but not the other way around. Lets presume I have the following code:
case class Preferences (
projectName: Option[String]
)
Now I have a formatter class that looks like this:
object PreferencesFormat {
def reads(obj: Option[Document]): Option[Preferences] = {
obj.map(preferences =>
Preferences(
preferences.get[BsonString]("project_name")
)
)
}
def writes(preferences: Preferences): Document = {
Document(
"project_name" -> preferences.projectName
)
}
}
I get an error with this when trying to read from the Document to the Preference object because of a type mismatch:
[error] found : Option[org.mongodb.scala.bson.BsonString]
[error] (which expands to) Option[org.bson.BsonString]
[error] required: Option[String]
[error] preferences.get[BsonString]("project_name")
String to BsonString works, but BsonString to String does not. Are we SOL here, or are we missing something? It seems like we have to write our own transformer to get this to work properly. Thanks for any clarity on this matter!