I am new to mongo, scala and salat
I have json collection as
{[
{"firstName":"John", "lastName":"Doe", department="IT", skills="java"},
{"firstName":"Anna", "lastName":"Smith", department="accounts, skills="tally"},
{"firstName":"Peter", "lastName":"Jones", department="It" skills="java" }
]}
I defined case class as below
case class Employee(firstName:String,lastName:String,department:String,skills:String)
used salatdao as below
object EmployeeDao extends SalatDAO[Employees, ObjectId](collection =employee_collection)
and method to get employees like this
def getEmployees(IT : String):List[Employees]={
val listOfEmployees:List[Employees] = OrderDAO3.find(MongoDBObject({"department"->IT})).toList
return listOfEmployees
}
get result as this...
{[ {"firstName":"John", "lastName":"Doe", department="IT", skills="java"}, {"firstName":"Peter", "lastName":"Jones", department="IT" skills="java" } ]}
so far so good,... Now I want to GROUP BY ALL DEPARTMENTS and want result like this
{"IT":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
{"accounts":[
{"firstName":"Johnac", "lastName":"Doeac"},
{"firstName":"Annaac", "lastName":"Smithac"},
{"firstName":"Peterac", "lastName":"Jonesac"}
]}
}
so please suggust me How would I write MongoDBObject to get this result and also suggest me the respective case class to hold that collection.
Could you please compile your answer with this information on yourself? ).
https://docs.mongodb.org/v3.0/reference/operator/aggregation/
https://docs.mongodb.org/v3.0/reference/operator/aggregation/match/
https://docs.mongodb.org/v3.0/reference/operator/aggregation/group/
Scala Play Salat Aggregate Example
Thank you ).