How to return multiple Mongoose collections in one get request?

后端 未结 3 993
北恋
北恋 2020-12-21 07:56

I am trying to generate a response that returns the same collection sorted by 3 different columns. Here\'s the code I currently have:

var findRoute = router.         


        
3条回答
  •  长情又很酷
    2020-12-21 08:06

    Have you tried ?

    Box.find().sort("-itemCount").exec(function(err, boxes) {
        res.json(boxes)
    });
    

    Also for sorting your results based on 2 or more fields you can use :

    .sort({name: 1, size: -1})

    Let me know if that helps.

提交回复
热议问题