With rogue, you can use :
.select()
In your case :
temp = place where (_.name matches p2) select(_.name, _.id) fetch()
More example are available here (go to line 174) : Rogue QueryTest.scala
Question
I have this:
temp = place where (_.name matches p2) fetch()
Now, what i have to do to get just two field of that results? For example name
and id
.
Thanks in advance :)
Solution
With rogue, you can use :
.select()
In your case :
temp = place where (_.name matches p2) select(_.name, _.id) fetch()
More example are available here (go to line 174) : Rogue QueryTest.scala
OTHER TIPS
please find below code for getting selected filed in mongodb.
db.user.find( { role: 'admin' }, { name: 1, id: 1 } )
You need to use the projection parameter which can limit the results to specific fields:
val q = MongoDBObject.empty
val fields = MongoDBObject("userid" ->, name" -> 1)
for (x <- mongoColl.find(q, fields)) println(x)
Assuming the basic connection and collections are properly referenced, the above code would return only userId
and name
.