Reputation: 2004
I'm having problems with queries in composer rest server.
I'm building a filter like this:
{
"where": {
"and": [
{
"origin": "web"
},
{
"affiliate": "resource:org.acme.affiliates.Affiliate#2"
},
{
"createdAt": {
"gte": "2018-01-01"
}
},
{
"createdAt": {
"lte": "2018-06-07"
}
}
]
}
}
request:
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'
response:
[
{
"$class": "org.acme.affiliates.User",
"affiliate": "resource:org.acme.affiliates.Affiliate#2",
"userId": "14",
"email": "[email protected]",
"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": "[email protected]",
"firstName": "diego",
"lastName": "algo",
"createdAt": "2018-04-20T20:53:40.720Z",
"origin": "web"
}
]
As you see, filters are not working because Affiliate#1 appears. I tested without createdAt filters and work perfectly, then i tested without affiliate and work good too. I tested with createdAt with range instead gte and lte with the same wrong result.
hlfv1
composer rest server v0.16.6
Upvotes: 1
Views: 490
Reputation: 2004
I answer my own question:
I was using hlfv1 and composer 0.16.6
After update to hlfv11 and composer 0.19.8 the bug is fixed.
Upvotes: 2
Reputation: 6740
its a loopback filter issue, most likely to do with the date range comparison. (the other comparisons are fine as you wrote).
The suggestion here -> https://github.com/strongloop/loopback-connector-mongodb/issues/176 would suggest that you need to use the between
operator instead for DateTimes. eg
{"where":{"createdAt":{"between": ['2018-01-05 10:00', '2018-05-10 10:00']}}}
Upvotes: 2