0

I am new to mongoDB and scala,

I have created case clase like

case class ABC(value1:String, Value2:String, Value3:Int)

and

case class ListOfABC(listofABC: List[ABC])

I have created implicit formater for json to string and vice versa for both classes

implicit formater..

and I am making call on ListOFABC in DAO object...but I am not getting result I am getting "List()" as output

can anybody sugget any working example of such scenario.. Or my design is right? I mean creating base class and making List of that class?

1 Answer 1

0

I recommend you to use casbah ans Salat

SalatDAO is a simple extensible DAO pattern that you can use out of box or as the basis for your own DAO implementation.

casbah is Scala toolkit for MongoDB

There are plenty of examples for example in here

import com.novus.salat._
import com.novus.salat.dao._
import com.novus.salat.global._

import com.mongodb.casbah.Imports._

case class Employee(_id:ObjectId = new ObjectId, name: String, age: Option[Int]=None, annual_salary: Option[BigDecimal]=None)

object EmployeeDAO
  extends SalatDAO[Employee, ObjectId](collection = MongoConnection()("salat_test")("employees"))

object App{
  def main(args:Array[String]){
    val employee = Employee(name="Foo")

    val id = EmployeeDAO.insert(employee)
    println("Inserted id:" + id)

    val found = EmployeeDAO.findOne(MongoDBObject("name" -> "Foo"))
    println("Found record for name ->Foo:" + found)

    val dbo = grater[Employee].asDBObject(employee)
    println("Converted DBObject:" + dbo)
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.