0
select _id from project where projectName = '***' order by viewCount desc limit 5

i'm still new to mongoose and have a somewhat intermediate SQL understanding, here's my attempt of it as i'm trying to retrieve the ObjectId of the sorted return

ProjectModel.find({id}).sort({viewCount: -1}).limit(5).exec( 
    function(err, projects) {
        ...
    }
);
bouncingHippo
  • 5,940
  • 21
  • 67
  • 107

1 Answers1

2
ProjectModel.find({projectName: '***'}, ["_id"]).sort({viewCount: -1}).limit(5).exec( 
    function(err, projects) {
        ...
    }
);
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • what does the `***` mean? if `projectName` is not null, return `_id` and sort it by `viewCount` and limit the results to 5? – bouncingHippo Nov 08 '12 at 21:13
  • See http://mongoosejs.com/docs/api.html#model_Model-find `{projectName: '***'}` is the `where projectName = '***'` equivalent of SQL – Esailija Nov 08 '12 at 21:13