Creating a high quality index for a frontend table multicolumn sorting


After having read the official documentation on indexes, in particular compound indexes, I have the following question:

Suppose in my front-end application I have a table similar to this:

The table contains the following columns: Name | Age | Manager | Start Date

Let’s imagine that these columns represent fields in a collection called “Employees”.

As seen in the picture, a user is supposed to be able to, among other things, sort the table results by any of the given fields:

a) individually
b) in a combined way

So for instance, it could be any of the combinations:

{name: 1, age: -1}
{age: 1, name: -1, startDate: -1}
{name: 1, age: 1, startDate: 1}
{age: -1, name: -1}
{startDate: 1}
{startDate: -1, age: 1}

… and so on…

Could you suggest an optimal strategy for implementing indexes for this flexible table sorting control in an efficient and scalable way?

Thank you

1 Like