문제

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 :)

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top