Question

I'm working on an API and would like it as efficient as possible. I have no obvious need to translate into case classes or any other strucrure besides the JSON I send to the client. Is there any easy way to extract JSON directly instead of row data -> class -> JSON. I'm open to use anorm, Slick, or anything else, I just need it to be lightweight.

If I were to use Mongo, shouldn't I be able to extract JSON from my store and transform it without having the overhead of deserializing to an object? Shouldn't I be able to use JSON <-> JSON?

Was it helpful?

Solution

Use Casbah as the MongoDB Scala driver.

For example, extracting the JSON stored in mongodb for your user with id==1 from mongodb becomes as easy as:

val obj : Option[DBObject] = db.users.findOne(MongoDBObject("user.id" -> 1))
val json : String = obj.map(_.get("user").toString)
                             .getOrElse(throw new Exception("error..."))

OTHER TIPS

Yes, just build your API over MongoDB as your datastore (http://www.mongodb.org/). Then you can store, and retrieve your data as JSON docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top