I try the Restful API with filter parameters below
filter={ "where": { "date": {"lte": "2014-06-05"} }}
But I can't find any record.
I have tried another field with int type
filter={ "where": { "price": {"lte": 123} }}
I am wondering if gt, get, lt, lte only works for int, float, not work for date type
Any suggestion?
Can you try IOS format, such as '2013-10-15T21:34:50.000Z'?
I have tried also, but it still not work.
I also try the code form.
HistoryPrice.find({
where: {
date: {gt: new Date('2013-06-05T21:34:50.000Z')}},
},
console.log
);
And it doesn't work.
what connector do you use?
I just use default connector, i.e. memory-connector
The memory connector only allows number comparison at this moment. We'll add support for other types.
Hi Raymond
Thanks for your quick reply. Might I know the which connector will support Date comparison, such as MongoDB, MySQL, or ....?
Real DBs should support date comparison.
Thanks, I have a small patch to support it if it's okay, I have tested it and it works fine.
https://github.com/strongloop/loopback-datasource-juggler/pull/131
Thanks
I'm having the same problem using the loopback-connector-mongodb 1.13.0.
Not work
{
"where": {
"status.created_at": {
"gte": "2015-09-13T15:30.000Z",
"lte": "2015-09-15T15:45.000Z"
}
}
}
Work
{
"where": {
"status.timestamp_ms": {
"gte": 1442169000000,
"lte": 1442342700000
}
}
}
I believe that is related to this issues #123 and #517 too
I had to use "and" operation to separate the lte and gte comparisons. If I use them together inside the same { } doesnt work.
Doesn't work:
{"where": { "epoch_time": {"lte":1459407675, "gte":1450717674} } },
Works:
{"where": {and: [{"epoch_time": {"gte":1450717674}},{"epoch_time": {"lte":1459407675}}]} }
I am also facing the same issue. @cchacons Solution worked :+1:
Not sure if your issue is the same as mine was, my query also was failing on a Date field (using MongoDB).
I describe my issue and my solution here: Post to LoopbackJS Google group
Basically, it boils down to not having explicitly assigned my related model field to be of type 'Date'.
Hope it helps.
@raymondfeng @cchacons any idea why this wouldn't be working for me? please help postgres-connector
Doesn't work (returns empty array)
const moment = require( 'moment' );
var
now = moment(),
yesterday = now.subtract( 24, 'hours' );
Model.find({
where: {
and: [
{ expiresOn: { gt: yesterday.toJSON() }},
{ expiresOn: { lte: now.toJSON() }}
]
}
});
works (same upper bound so i know there is data i should be getting from the first query)
const moment = require( 'moment' );
var
now = moment(),
yesterday = now.subtract( 24, 'hours' );
Model.find({
where: {
expiresOn: { gt: yesterday.toJSON() }
}
});
Nevermind I was having a moment with moment.
...
now = moment(),
yesterday = moment( now ).subtract( 24, 'hours' ); // you have to create a new moment instance to get yesterday, otherwise now and yesterday will be the same ( resulting in empty data :x)
...
Thanks @spirospolitis !
I also faced the same issue.聽Thanks to @cchacons聽for the solution. But it must be mentioned in official docs.
Most helpful comment
I had to use "and" operation to separate the lte and gte comparisons. If I use them together inside the same { } doesnt work.
Doesn't work:
{"where": { "epoch_time": {"lte":1459407675, "gte":1450717674} } },
Works:
{"where": {and: [{"epoch_time": {"gte":1450717674}},{"epoch_time": {"lte":1459407675}}]} }