Search code examples
stronglooploopback

Using or and between together in Loopback restful api filter


I am facing the problem of this. If I want to apply this kind of filter in loopback restful api filter.

between(0,7) or between(11,17) or between(21,27)

How to write the filter script?


Solution

  • In code:

    var myFilter = {
      where: {
            or: [{
                val: {
                    between: [0, 7]
                }
            }, {
                val: {
                    between: [11, 17]
                }
            }, {
                val: {
                    between: [21, 27]
                }
            }]
        }
    };
    
    MyModel.find(myFilter, function (err, instances) {
      // Code to apply on found instances 
    });
    

    You can use a stringified JSON version of a filter in your REST queries.