javascript - Reversing the .each() order (mongodb) -


using mongodb mongoose:

my current code returns correct docs sends them client in wrong order. tried adding sort command after .limit() reverse hasn't been working well. ideas make happen within db call instead of code reverse order?

item.find().sort('_id','descending').limit(40).each(function(err, doc) {     if(doc != null){         client.send(json.stringify(doc));            } }); 

how this?

var orderedlist = new array(); item.find().sort('_id','descending').limit(40).each(function(err, doc) {     orderedlist.push(doc); });  (var i=orderedlist.length; i>=0; i--){    orderedlist[i].doyourthang.. } 

try: jquery .each() backwards reverse() plugin


Comments