I'm new with Salat,Casbah and MongoDB. When I've been trying to make a simple method to get all users from db,
import DAL.Instances.User.{UserDAO, User}
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.annotations._
import com.novus.salat.dao._
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.MongoConnection
object UserRepository {
def getAllUsers() = {
val userList= UserDAO.find()
userList.isEmpty match {
case true => throw new Exception("None users in your db")
case false => userList
}
}
I faced with two errors:
Error:(29, 31) No implicit view available from Unit => com
.mongodb.DBObject.
val userList= UserDAO.find()
^
Error:(29, 31) not enough arguments for method find: (implicit evidence$2: Unit => com.mongodb.DBObject)com.novus.salat.dao.SalatMongoCursor[DAL.Instances.User.User].
Unspecified value parameter evidence$2.
val userList= UserDAO.find()
^
Here is my User code:
object User {
case class User( _id: ObjectId = new ObjectId, name:String, age:Int)
object UserDAO extends SalatDAO[User, ObjectId](collection = MongoConnection()("fulltestdb")("user"))
}
I'm not sure what version of
Salatyou are using but if you look at the signature forfindit'll give you a clue as to what the issue is:You need to call
findwith a parameter that has a view bound so that this parameter may be viewed as aDBObject. This means that an implicit conversion fromA => DBObjectis expected to be in scope.In your case you aren't passing any parameter. This is being treated as
Unitand so the compiler tries to find an implicit conversion fromUnit => DBObject. This can't be found so compilation fails.To fix this you're best bet is to pass in an empty DBObject, you can achieve this with
MongoDBObject.emptyfrom casbah. You could add an implicit conversion fromUnit => MongoDBObjectbut I'd probably lean towards making it explicit where possible.