strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

greater and less than where clause is not working togather #2886

Closed shyam2k16 closed 7 years ago

shyam2k16 commented 7 years ago

Hello,

I want to fetch datewise data but i am not getting desired output. I am using this {"createdAt":{"gt":"2016-10-18","lt":"2016-10-21"}} in where clause to fetch data .. but it is giving all the records. Individullay i am gtting correct response but when I am using gt and lt togheter it is giving all the data

Any help would be appreciable..

Please suggest.

phra commented 7 years ago

is this confirmed? @shyam2k16 do you get the same result if you split the query object like {"createdAt":{"gt":"2016-10-18"}, "createdAt":{"lt":"2016-10-21"}} ?

jannyHou commented 7 years ago

@shyam2k16 @phra I think the right format is

where: {
  and: [
    {createdAt: {gt: '2016-10-18'}},
    {createdAt: {lt: '2016-10-21'}}
  ]
}

Please see our doc for where filter to know more about how to use and/or: https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-and/or

phra commented 7 years ago

@jannyHou yeah, i was remembering that were splitted in some way. thank you.

jannyHou commented 7 years ago

:+1: We use git to track features and bugs and I am closing this issue since problem solved. Feel free to reopen it if you have other questions :) Thanks for understanding.

shyam2k16 commented 7 years ago

Thank you @jannyHou .. It's working!

ruoru commented 7 years ago

i suggest use between like this:

where: {
    createdAt: between['2016-10-18', '2016-10-21'],
}
phra commented 7 years ago

@ruoru maybe in this way.

where: {
    createdAt: { between: ['2016-10-18', '2016-10-21'] }
}
ruoru commented 7 years ago

@phra sorry,my writing is wrong, thanks.