0

Is there a way to set a max limit in Loopback. I imagine something like this:

MyModel.paginateFind = function(filter, page, cb){

    // Set max limit of 1000
    if (filter.limit > 1000) filter.limit = 1000;

    // Set pagination
    filter.skip = filter.limit * (page - 1);

    // Call the standard find function with the new filter
    MyModel.find(filter, function(err, res){
        cb(err, res);
    });
}

MyModel.remoteMethod(
    'paginatedFind',
    {
        http: {path: '/', verb: 'get'},
        accepts: [
            {arg: 'filter', type: 'object'},
            {arg: 'page',   type: 'number'}
        ],
        returns: {arg: 'result', type: 'object'}
    }
);

This works when the filter is formated as json, but not in this format: http://localhost:3000/api/MyModel?filter=[where][country]=DE. How can I use the standard StongLoop filter format?

Geoffrey Burdett
  • 1,906
  • 1
  • 14
  • 26
  • Are you maybe looking for the `limit filter` which goes hand in hand with the `skip filter`? http://docs.strongloop.com/display/public/LB/Limit+filter – pulkitsinghal Jun 09 '15 at 15:49
  • Yes, but I don't know how to manipulate the filter in a custom function/end-point in the model. I'm sure it's something super simple. – Geoffrey Burdett Jun 09 '15 at 17:14
  • Your pseudo-code looks pretty accurate~ish to me ... have you asked on https://gitter.im/strongloop/loopback already? – pulkitsinghal Jun 09 '15 at 20:51

1 Answers1

0

The format, according the to documentation here should look like this:

api/MyModel?filter[where][country]=DE
JSimonsen
  • 2,642
  • 1
  • 13
  • 13