作曲家休息服务器中的查询过滤器

Query filter in composer rest server

我在 composer rest 服务器中遇到查询问题。

我正在构建这样的过滤器:

{
    "where": {
        "and": [
        {
            "origin": "web"
        },
        {
            "affiliate": "resource:org.acme.affiliates.Affiliate#2"
        },
        {
            "createdAt": {
            "gte": "2018-01-01"
            }
        },
        {
            "createdAt": {
            "lte": "2018-06-07"
            }
        }
        ]
    }
}

要求:

curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/User?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22origin%22%3A%22web%22%7D%2C%7B%22affiliate%22%3A%22resource%3Aorg.acme.affiliates.Affiliate%232%22%7D%2C%7B%22createdAt%22%3A%7B%22gte%22%3A%222018-01-01%22%2C%22lte%22%3A%222018-06-07%22%7D%7D%5D%7D%7D'

回复:

[
    {
        "$class": "org.acme.affiliates.User",
        "affiliate": "resource:org.acme.affiliates.Affiliate#2",
        "userId": "14",
        "email": "diego@duncan.com",
        "firstName": "diego",
        "lastName": "duncan",
        "createdAt": "2018-04-20T20:48:08.151Z",
        "origin": "web"
    },
    {
        "$class": "org.acme.affiliates.User",
        "affiliate": "resource:org.acme.affiliates.Affiliate#1",
        "userId": "15",
        "email": "diego@algo.com",
        "firstName": "diego",
        "lastName": "algo",
        "createdAt": "2018-04-20T20:53:40.720Z",
        "origin": "web"
    }
]

如您所见,过滤器不起作用,因为出现了 Affiliate#1。 我在没有 createdAt 过滤器的情况下进行了测试并且工作完美,然后我在没有附属公司的情况下进行了测试并且工作也很好。我用带有范围的 createdAt 而不是 gte 和 lte 进行了测试,结果相同。

hlfv1

composer rest 服务器 v0.16.6

这是一个环回过滤器问题,很可能与日期范围比较有关。 (你写的其他比较没问题)。

这里的建议 -> https://github.com/strongloop/loopback-connector-mongodb/issues/176 会建议您需要对 DateTimes 使用 between 运算符。例如

{"where":{"createdAt":{"between": ['2018-01-05 10:00', '2018-05-10 10:00']}}}

我回答我自己的问题:

我使用的是 hlfv1 和 composer 0.16.6

更新到 hlfv11 和 composer 0.19.8 后,错误已修复。