Hi Suchita,
To output associated fields or columns related to ref_ward_id, you can use $lookup in the aggregation.
$lookup (aggregation) stage has the following syntax :
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
For example, in your case:
db.ls_census_user_mapping.aggregate([
{ $group: { _id: "$ref_ward_id" , count : { $sum: 1 }}
},
{ $match: { count : { $gt : 1 }}
},
{ $lookup:
{ from: "census_user_mapping", localField: "_id", foreignField: "ref_ward_id", as: "new_dup" }
}
])
Where:
census_user_mapping is the collection you are finding duplicate records from.
“_id” is the local field to use and foreignField is “ref_ward_id”.
new_dup is the field which will display all data related to ref_ward_id in an array.
Regards,
Lian