Strongloop Loopback Where Or filter in REST 语法

Strongloop Looback Where Or filter in REST syntax

我需要查询where descr like 'xxx' or short_descr like 'xxx'

我知道 how to do 它使用:

{"where": {
      "or": [
        {"description": {"like": "xxx"}},
        {"short_description": {"like": "xxx"}}
      }
    }
}

但需要在 REST 语法中添加查询参数。

我正在尝试:

params['filter[where][or]'] = JSON.stringify([
                { "description": { "like": "xxx" } },
                { "short_description": { "like": "xxx" } }
              ])

结果为 The or operator has invalid clauses

这里有一个例子(我用 'desc' 而不是 'description'):

http://localhost:3000/api/cats?filter[where][or][0][desc][like]=foo&filter[where][or][1][short_desc][like]=goo

所以重要的部分是:

  • 首先,你需要给OR子句的每一部分一个索引。注意第一个是0,然后是1。
  • 其次 - 嗯...我以为我有更多,但仅此而已。

有关 WHERE 过滤器的更多信息:https://docs.strongloop.com/display/LB/Where+filter