How to sort a populated document in find request?

前端 未结 7 1444
挽巷
挽巷 2020-11-28 09:52

I would like to sort a populated Document from the collection i fetch, i get an error requesting it.

Let\'s admit a Document Group (Group) and \'Member\

7条回答
  •  囚心锁ツ
    2020-11-28 10:16

    You can also implicitly specify only required parameters of populate:

    Group
      .find({})
      .populate({path: 'Members', options: { sort: { 'created_at': -1 } } })
    

    Have a look at http://mongoosejs.com/docs/api.html#document_Document-populate

提交回复
热议问题