I have a model which looks like
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc41"),
"refid" : 1,
"item" : "xyz1",
"qnid" : 1
}
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc42"),
"refid" : 1,
"item" : "xyz2",
"qnid" : 2
}
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc43"),
"refid" : 1,
"item" : "xyz3",
"qnid" : 3
}
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc44"),
"refid" : 4,
"item" : "xyz4",
"qnid" : 4
}
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc45"),
"refid" : 4,
"item" : "xyz5",
"qnid" : 5
}
here refid is the reference id for the article and qnid is the actually id which holdes the version. i want to fetch all the articles ie refid with recent version data.
i want to get the recent records aggregated by refid
article refid 1 has qnid 3 as the recent one. article refid 4 has qnid 5 as the recent one. ie
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc43"),
"refid" : 1,
"item" : "xyz3",
"qnid" : 3
}
{
"_id" : ObjectId("5b975b7ffb8361fa0cdacc45"),
"refid" : 4,
"item" : "xyz5",
"qnid" : 5
}
Please help me how can i do this. I used aggregate function with sort but it is not giving the data