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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -