edwardhotchkiss / mongoose-paginate

Mongoose.js (Node.js & MongoDB) Document Query Pagination
MIT License
984 stars 217 forks source link

sort populate field not working #142

Open kodelio opened 6 years ago

kodelio commented 6 years ago

Hi,

I'm trying to sort my results with a field which is inside a populate :

let query   = {$or:[{name: { "$regex": params.search, "$options": "i" }}, {_id: { "$regex": params.search, "$options": "i" }}]};

let options = {
     offset: params.offset,
     limit: params.limit,
     populate: {
          path: '_id',
          options: {
              sort: {
                  'MktCapUSD': -1
               }
           }
     }
};

return Models.Asset.paginate(query, options).then(function (result) {
    return result;
}).catch((err) => {
    throw err;
});

But it's ignoring my sort query.

Rathunter commented 6 years ago

I am experiencing the same issue which makes me abandon this plugin and use Mongo's aggregate function instead. If this ever resolved please let me know.