I have a mongo collection named feetransaction that contain batch wise transaction record of students.
Since a student can make multiple payments, each student can have multiple transaction records.
I want to get last feetransaction record for each student for requested batch in a single query. My mongo domain is as follows:
{
"_id" : ObjectId("56e0ce6ba094a91976e708b6"),
"studentId" : "56e0ce6aa094a91976e7048e",
"studentName" : "XYZ",
"batchId" : "56e0ce6aa094a91976e70003",
"batchName" : "10 - A",
"payableAmount" : 200,
"paid" : 850,
"prevBal" : 0,
"balance" : -650,
"createdDate" : ISODate("2016-03-10T01:31:22.505Z")
}
{
"_id" : ObjectId("56e0ce6ba094a91976e708b6"),
"studentId" : "56e0ce6aa094a91976e7048e",
"studentName" : "ABC 1",
"batchId" : "56e0ce6aa094a91976e70003",
"batchName" : "10 - A",
"payableAmount" : 200,
"paid" : 850,
"prevBal" : 0,
"balance" : -650,
"createdDate" : ISODate("2016-03-10T01:31:22.505Z")
}