My mongo data as follows.
{
"date" : Jan,
"rank" : 1,
"StudentId: 10
},
{
"date" : Jan,
"rank" : 1,
"StudentId: 20
},
{
"date" : Jan,
"rank" : 2,
"StudentId: 30
},
{
"date" : Feb,
"rank" : 1,
"StudentId: 10
},
{
"date" : Feb,
"rank" : 2,
"StudentId: 20
},
{
"date" : Feb,
"rank" : 3,
"StudentId: 30
}
I would like to get the desired result as the moved ranks from 1 to 2 with month movement from Jan to Feb. ie. From the above json I want the below result
{
"date" : Feb,
"rank" : 2,
"StudentId: 20
}
ie.. The from date is Jan, to date is Feb, from date rank is 1 and to date rank is 2.
How can I achieve this using the mongo db query???