Search code examples
mongodbloopbackjsstrongloop

Sorting in Loopback Connector Mongo


I'm having a real issue. I'm trying to do a query, limit, sort, etc. This is what I'm doing:

MyModel.find( { where: { "location": 
                       { "near": { "lat": "80", "lng": 80 }}
              },
              {  limit: 50, offset: 0, skip: 10,
                 sort: { "name": "asc" }
              }, 
              function(err, docs) {
                  var retval    = docs || [];
                  return cb(null, retval);
           });

What is the magic sauce to do limit, skip, and sort?

Any help is appreciated. Thanks


Solution

  • MyModel.find( { where: { "location": { "near": { "lat": "80", "lng": 80 }}},
                limit: 50,
                offset: 0, 
                skip: 10, 
                order: "name ASC"
              }, 
              function(err, docs) {
                  var retval    = docs || [];
                  cb(null, retval);
           });
    

    I think this is the way it should look. try reading this and documentation under it: https://docs.strongloop.com/display/public/LB/Querying+data