I need to make a block for the page of one product where the bottom will be “You will also like it” and there is a list of 4 products with the same category. But how is it better to do the sorting so that the API server router.get products by category router.get or is it better to get everything and then sort it on the client?

If on the client, then how can I select from the array only those products for which productType and gender will be the same.

And if through the server, you can show how to sort through find , as I understand how only findById

Here is how I did it to do it through a separate router :

 router.get('/sort/:sortBy',(req,res,next) => { Product.find({ gender : req.body.gender}) .then(response => { res.status(200).json(response) }) .catch(err => { res.status(500).json({ error: err }) }) }) 

But how can I make the value recorded in sortBy instead of gender? So that when searching by any parameter I can use one method.

I use Node.js, Express.js, Vue.js, Mongoose, MongoDB

    0