【问题标题】:loopback.io: Not In queryloopback.io:不在查询中
【发布时间】:2015-11-09 18:02:20
【问题描述】:

我正在尝试在 loopback.io 中执行 not in 查询。但找不到与此相关的任何功能。这是我尝试过的:

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

而实际上生成的查询是:

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

我知道我们可以检查一下

field in (n1,n2,...)

使用https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-inq。但我无法得到“不在”的情况。

以前有人遇到过这种情况吗?

【问题讨论】:

    标签: loopbackjs strongloop


    【解决方案1】:

    您使用的是neq,它确实用于您提供的不等于。 要使用Not In 运算符,我们必须使用nin。再次检查documentation,有一个表格,上面有操作员及其描述

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

    【讨论】:

    • 愚蠢的我.. 没有注意到 nin 运算符。谢谢@Vishal
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    相关资源
    最近更新 更多