Hi i want to get the distict values in mongodb.
this is my example table
Name________________Age___________________Salary
x ___________________ 25 ___________________5000
x ___________________ 25 ___________________5000
x ___________________ 26 ___________________5000
y ___________________ 25 ___________________5000
y ___________________ 26 ___________________5000
I want to get the result like this
{
"Name" : "x",
"Age" : [
{
25,26
}]
}
{
"Name" : "y",
"Age" : [
{
25,26
}]
}
is there any way to get the result like this.
my sql query is
select distinct Name,Age from Table where salary=5000
i tried like this
but this is not able to get like this
db.getCollection('Table').aggregate([
{"$match":{Salary:5000}},
{"$group":{_id:{Name:"$Name",Age:"$Age"}}},
{"$project" : {_id:0, Name:"$_id.Name", Age:"$_id.Age"}}
])