db.users.aggregate(
{$match :
{"_id" : ObjectId("50f69176904e1d66affec20d")}
},
{$unwind : "$connections"},
{$match :
{$or : [
{"connections.users" : {$exists : false}},
{"connections.users.id" : "50f651b8b58bba7fbec2f223"}
]}},
{$group : {_id : "$connections.group"}}
)
Here I am finding the group names in which specific user exists. I am getting the correct result in mongodb shell. Now I have to use it in the lithium framework. Please help me with the command. For collection structure, see this link : http://pastebin.com/P8uMw9cj
You should read Tom Maiaroto's article "MongoDB Aggregation of all Shapes and Sizes"
It covers Map/Reduce, Grouping and The New Aggregation Framework