case class Venue(@Key("_id") id: Int,
location: Tuple2[Double, Double],
name: String)
object VenueDAO extends SalatDAO[Venue, Int](collection = MongoConnection()("ec")("venue"))
VenueDAO.find(?) //return Option[Venue]
How to search data by location using Salat?
Two things to start out:
In any case, since Salat doesn't support Tuples, here is what you can do:
case class Location(x: Double, y: Double)
case class Venue(@Key("_id") id: Int, location: Location, name, String)
val venue = Venue(1, Location(1.0, 1.0), "NYC")
VenueDAO.save(venue)
println(s"Saved: $venue")
val found = VenueDAO.findOne(MongoDBObject("location.x" -> 1.0, "location.y" -> 1.0))
println(s"Found: $found")
Prints:
Saved: Venue(1,Location(1.0,1.0),NYC)
Found: Some(Venue(1,Location(1.0,1.0),NYC))