MongoDb Distinct query

35 views
Skip to first unread message

Chris Hagan

unread,
Jul 6, 2011, 3:53:07 AM7/6/11
to Lift
Hi Lifters!

I apologise if this is retreading old ground, but could anyone point
me towards a way to execute the following query:

> db.userinformations.distinct("groups")

in mongodb-record?

What I've had to settle for at the moment is

Set(UserInformation.findAll.flatMap(_.groups.is))

which is not, of course, the same thing at all.

Thanks!

c

Chris Hagan

unread,
Jul 6, 2011, 6:44:25 AM7/6/11
to Lift
Ah, for posterity, here's one solution. I'm eager to hear a more
expert one though!

MongoDB.useCollection("userinformations")(_.distinct("groups"))

c

Tim Nelson

unread,
Jul 6, 2011, 10:05:18 AM7/6/11
to lif...@googlegroups.com
Hi Chris,

That's the way to do it. If you write it inside your MetaRecord object there's a useColl function that would use the collection name defined directly, so you could just write:

def distinctGroups = useCall(_.distinct("groups"))

Tim

Chris Hagan

unread,
Jul 8, 2011, 3:19:21 AM7/8/11
to Lift
Thanks very much, Tim. It did indeed to turn out to be very neat that
way.

c
Reply all
Reply to author
Forward
0 new messages