davidgtonge / underscore-query

MongoDB like query api for JavaScript Arrays

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Complex equries doesn't work(But works fine on mongo)

mbalyaba opened this issue · comments

Hi!
It seems like my complex query work incorrect.
I have a query with "$or" inside "$and" item.
Tested on mongo it works. But with underscore-query no.
Please check this problem or tell if I'm doing something wrong.
Thanks!
Example:
{ "$and": [{ "username": "test@mail.com" }, { "$or": [{ "startDate": { "$lte": "2016-07-08 23:59:59:999" } }, { "startDate": null }] }, { "$or": [{ "finishDate": { "$gte": "2016-07-08" }, "habitStatus": { "$in": ["CANCELLED", "COMPLETE"] } }, { "habitStatus": "WIP" }] }] }

They work for me, make sure you're on the latest version of the library

ok, I'll try again. I can take latest version here https://github.com/davidgtonge/underscore-query/tree/master/lib right ?

Yep, that should work

It seems like problem is in parseParamType function. maybe

I ran your query on node without issue. Are you getting a crash or is it just not returning your expected result?

For reference https://github.com/davidgtonge/underscore-query/blob/master/test/suite.coffee#L369

it is returns empty array, but mongo at the same time returns array with data

can you show your query please ?

I think the issue is compound $ands

a =  [
  {title:"Home", colors:["red","yellow","blue"], likes:12, featured:true, content: "Dummy content about coffeescript", score: 0}
  {title:"About", colors:["red"], likes:2, featured:true, content: "dummy content about javascript", score: 5}
  {title:"Contact", colors:["red","blue"], likes:20, content: "Dummy content about PHP", score: -1, total:NaN}
]

result = _query(a, {
  $and: [{
    $and: [ likes: {$gt: 5 } ]
  }]
})

# result is empty

result = _query(a, {
  $and: [{
    likes: {$gt: 5 }
  }]
})

# result has 2 items

so issue is in underscore-query, right ?

Looks like it

On Fri, Jul 8, 2016 at 11:12 AM, mbalyaba notifications@github.com wrote:

so issue is in underscore-query, right ?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#29 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ADUIEPQ4LR5WDEz95KXkTGpReSzfCFVvks5qTmjVgaJpZM4JIBoB
.

ok. Hope it will be fixed in the nearest future)
Thanks!

Thanks @mbalyaba for reporting the issue and @megawac for diagnosing it.
I've pushed a fix :-)

added this is a test case to https://github.com/davidgtonge/query-predicate - it passed without any modifications :-)

🎉 good stuff David