i'm writing a play 2.3.2 application. In my application i use a MongoDB database. I've a recommendation.tags and recommendation.request collections. They has the following JSON format: 1) recommendation.tags:
{
"_id" : ObjectId("542e65fb7ab45a4189944137"),
"tag" : "Meat:Pork - Bacon Cooked Slcd"
}
2) recommendation.requests
{
"_id" : ObjectId("542e67e07f724fc2af28ba74"),
"id" : "6649fd2b-c616-4693-aec5-a2a2a1658417",
"user" : {
"id" : "",
"email" : "alberto@gmail.com"
},
"tags" : [
{
"tag" : "Fish:Swordfish Loin Portions"
},
{
"tag" : "Vegetable:Carrots - Jumbo"
}
],
"date" : 1412327392380
}
I'm writing a Controller that handle all the statistics request. In this case i'm writing a method that search the most used tag in the system. For do that i'm using the reactive mongo driver for scala. This is the code used:
/**
* Method that search the most used tag.
*/
def max = Action {
var max = 0
var tag = null
val tags: Future[List[Tag]] = Tags.find(Json.obj()).toList
for{
tag <- tags
tagsOk <- Requests.find(Json.obj("tags.tag" -> tag.category + " " + tag.name)).count
if(tagsOk > max) {
max = tagsOk
tag = tag.category + " " + tag.name //string tag
}
}
Ok(tag)
}
But the compiler give me the following errors:
[error] /Users/alberto/git/bdrim/modules/recommendation-system/app/recommendationsystem/controllers/manager/StatisticsController.scala:28: identifier expected but string literal found.
[error] tagsOk <- Requests.find(Json.obj("tag" : tag.category + " " + tag.name)).count
[error] ^
[error] /Users/alberto/git/bdrim/modules/recommendation-system/app/recommendationsystem/controllers/manager/StatisticsController.scala:33: ')' expected but '}' found.
[error] }
[error] ^
[error] two errors found
[error] (compile:compile) Compilation failed
What's wrong??
@edit
[error] /Users/alberto/git/bdrim/modules/recommendation-system/app/recommendationsystem/controllers/manager/StatisticsController.scala:28: value category is not a member of List[recommendationsystem.models.Tag]
[error] tagsOk <- Requests.find(Json.obj("tags.tag" -> tag.category + " " + tag.name)).count
[error]
@newedit
I've solved using this code:
val tags = for{
tags <- futureTags
}
for(document <- tags) {
val tagsOk = Requests.find(Json.obj("tags.tag" -> document.category))
}
Is there a way to get the List[T] and after iterate on it in the same for??