Sort with alert type name eg:
{
"$sort": {
"alertTypeRel.alertTypeName": 1
}
},
{ $limit: 10 }
is that an
or just an example
honestly I can’t see how the alphabetic order of the alert types can be useful. I have no idea about the distribution of the alert types. but if i suppose that your first alert type, let’s say aaa
has more than 10 alerts. your pipeline will inconsistently chose 10 documents having an aaa
alert type. If that’s the sort of behavior you’re seeking, why don’t you $match
on "alertTypeRel.alertTypeName" :"aaa"
.
Or better get the _id
of the aaa
alert type from the collection AlertTypes
and $match
on "alertTypeId" :ObjectId("aaa's _id")
. That will save you the lookup and sort stages.
This is a work around solution. However, more importantly, you need to review your data base design. Check the design patterns I pointed out previously
Respect,
Thanks for your response.
If there are no 10 alerts belongs to the alert type as you told, we should fetch the alerts belongs to the second alert type rt.
As you can see in the attached image, there is a sortable column called alert type which fetches the alerts based on the alert type name either in ascending/descending order.
Hi
I already checked it. And I can’t help except to suggest a redesign of the data base.
I suggested a work around for the sort by type. and it looks like it can’t work because the database contains some test data.
Best regards,
Okay, will check it, Thanks