Hello @turivishal, thank you
I took some screenshots of what you recommended, and as we can see the console print the two query parameters when logging sortBy (here I tried with price and duration). Also we can see on postman that, the results are correct for the first parameter (price) but not the second (duration), they are not sorted by duration.
I think the issue is that the sort parameters was somehow not passed properly into mongoose. However, the code example you posted and the screenshot are showing different things: the code example looks like it’s one script, while the screenshot shows that the sorting processing was done in a function called sort().
What I would do in this situation is to manually step through the code to make sure that all the parameters are processed correctly, and the mongoose query was constructed correctly.
If you need further help, could you post a self-contained code that can reproduce this? E.g., you mentioned that this was called using the URI 127.0.0.1:3000/api/v1/tours?sort=ratingsAverage,price so I would also include the basic Express (?) code, so that we can work from a common source and not guessing on how your Express code looks like (and end up diverging since I could code it differently )