loopback.io: Not In query
Asked Answered
F

1

5

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?

Firebrand answered 9/11, 2015 at 8:37 Comment(0)
B
9

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) {...}
Belier answered 9/11, 2015 at 9:54 Comment(1)
silly me.. didn't notice the nin operator. Thanks @VishalFirebrand

© 2022 - 2024 — McMap. All rights reserved.