mongoose - How to sort a populated document in find request? -
i sort populated document collection fetch, error requesting it.
let's admit document group
(group) , 'member' (group.members)
group .find({}) .populate('members')
works perfectly, sort this:
group .find({}) .populate('members', ['_id', 'name'], null, { sort: [[ 'created_at', 'desc' ]] })
i error typeerror: invalid select() argument. must string or object.
adding this...
you can implicitly specify required parameters of populate:
group .find({}) .populate({path: 'members', options: { sort: { 'created_at': -1 } } })
have @ http://mongoosejs.com/docs/api.html#document_document-populate
Comments
Post a Comment