Search code examples
loopbackjsstrongloop

loopback.io: Not In query


I'm trying to do a not in query in loopback.io. But couldn't find any feature related to that. Here is what I have tried:

Product.find({
        where: {
            name: {
                like: '%' + searchTerm + '%'
            },
            id: {
                neq: [1,2,3]
            }
        },
        limit: 15
    }, function(err, searchResults) {...}

And in fact the query generated is:

'SELECT `id`,`name`,`ref` FROM `Product` WHERE `name` LIKE \'%iPh%\' AND `id`!=1, 2, 3 ORDER BY `id` LIMIT 15' }

I know we can check

field in (n1,n2,...)

using https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-inq. But I can't get the 'not in' case.

Anybody has come across this scenario before?


Solution

  • You were using neq which in indeed used for not equals as provided by you. To use Not In operator, we must use nin. Check the documentation again, there is a table with operators with their description

    Product.find({
        where: {
            name: {
                like: '%' + searchTerm + '%'
            },
            id: {
                nin: [1,2,3]
            }
        },
        limit: 15
    }, function(err, searchResults) {...}