How to get some certain field only from a recordset?

136 views Asked by At

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

3

There are 3 answers

1
Anthonny On BEST ANSWER

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

0
WiredPrairie On

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.

0
Vishal Ranapariya On

please find below code for getting selected filed in mongodb.

db.user.find( { role: 'admin' }, { name: 1, id: 1 } )