Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala & mongoDB - how to count records with salat?

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

like image 319
opensas Avatar asked Oct 26 '25 06:10

opensas


1 Answers

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))
}
like image 101
opensas Avatar answered Oct 29 '25 04:10

opensas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!