Some Loopback endpoints are ignoring dates - and it's infuriating!

266 views
Skip to first unread message

cliff....@tpv-tech.com

unread,
Apr 5, 2018, 10:36:14 AM4/5/18
to LoopbackJS
Hi there - we're using the following:

  • Loopback 3.0 (with the Postgresql connector)
  • Node v6.12.3

..and an Angular front end.

I'm trying to retrieve both the count of records between two dates and the records that also fall between these dates.

If I call* the API 'count' endpoint with this URL:


..I get a count of the items within that date range and I see this in the debug console:

  • loopback:connector:postgresql SQL: SELECT count(*) as "cnt" FROM "public"."sasdevices" WHERE "first_conn" BETWEEN $1 AND $2
  • loopback:connector:postgresql Parameters: ["2018-04-01","2018-04-09"] 

And I get a valid count of the records between those dates, which is everything I would expect.

However, if I call the 'find' endpoint with the same parameters, like either of these:


..then the debug console shows this:

  • loopback:connector:postgresql SQL: SELECT (list of fields) FROM "public"."sasdevices" ORDER BY "deviceid" 

...and then tries to return all 2 million+ records, crashing the server. Less than ideal.

I've also tried the JSON formatted requests from Postman and discovered that while this doesn't work:


..this request does:

But if I add the '["where":' to the request in the code, I get an error that the dates could not be processed.

Why is the 'find' endpoint not honouring the dates provided? 


(* Doesn't matter if I use code, the Loopback API Explorer or Postman, the results are the same.)

Mark Johnson

unread,
Apr 8, 2018, 7:28:58 PM4/8/18
to LoopbackJS
It looks like it's not working because you're not nesting "where" inside "filter" for find.  where is only a top level property for count because the filter properties are otherwise useless.
So you need filter[where][...]..
Reply all
Reply to author
Forward
0 new messages