How to sort a populated document in find request?

前端 未结 7 1432
挽巷
挽巷 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条回答
  •  Happy的楠姐
    2020-11-28 10:17

    This example above works with Mongoose 2.x and above, use this syntax:

    Group
      .find({})
      .populate('Members', '_id name', null, { sort: { 'created_at': -1 } })
    

提交回复
热议问题