Hi Srinivas,
From MongoDB version 2.2, you can use the
$group operator in the aggregation framework to group documents.
The aggregation command for the "GROUP BY" query is as below. You would need to update the code to run the same function using the driver.
{code}
db.collection.aggregate([
{ $match : { $or : [ {mid : 1}, {yid : 1} ] }},
{ $group : { _id : { mid : "$mid", yid : "$yid" } }},
{ $project:{ _id : 0, mid : "$_id.mid", yid : "$_id.yid" }}
])
{code}
From MongoDB version 2.5.2, you can use the
$setUnion operator in the aggregation framework to provide unions of data sets.
The aggregation command for the UNION query is as below:
{code}
db.collection.aggregate([
{ $match : { $or : [ {mid:1},{yid:1} ] } },
{ $group : { _id : null, mids : { $addToSet : "$mid" }, yids : { $addToSet : "$yid" }}},
{ $project : { _id : 0, mids_yids : { $setUnion : ["$yids", "$mids"]}}}
])
{code}
Please note that MongoDB 2.5 release is a development release for the production 2.6 release. Currently the latest version is 2.6 release candidate 2.6.0-rc0.
Thanks,
Linda