scala & mongoDB - how to count records with salat?

782 Views Asked by At

Is it possible to issue a count() query, with several conditions, using salat library?

right now I'm just doing something like

def countByPoll(pollId: String, option: Int): Int = {
  dao.find(
    MongoDBObject("pollId" -> pollId, "option" -> option)
  ).size
}

But I'm sure a count would perform much better

1

There are 1 best solutions below

0
On BEST ANSWER

I had a look at salat sources and it was easier than expected

def countByPoll(pollId: String, option: Int): Long = {
  dao.count(MongoDBObject("pollId" -> pollId, "option" -> option))
}