Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND Queries With Multiple Expressions Specifying the Same Field do not work #20

Closed
hogpilot opened this issue Nov 30, 2020 · 2 comments · Fixed by #21
Closed

AND Queries With Multiple Expressions Specifying the Same Field do not work #20

hogpilot opened this issue Nov 30, 2020 · 2 comments · Fixed by #21

Comments

@hogpilot
Copy link
Contributor

The following does not return as expected:

getMongoQuery('field > 1 AND field < 5')
> { field: { "$lt": 5 } }

Expected result:

{ "$and": [ { field: { "$gt": 1 }}, { field: { "$lt": 5 } } ] }
// OR
{ field: { "$gt": 1, "$lt": 5 } }
@orgoldfus
Copy link
Owner

@hogpilot - In such cases, I find it clearer to use the BETWEEN operator, which is already supported.
However, it should work with this syntax as well.

@hogpilot
Copy link
Contributor Author

hogpilot commented Nov 30, 2020

That's true, and what I had been doing for that specific numeric example. However, it doesn't work with strings or mixed types, which is why I found this issue.

For example:
getMongoQuery('field IS NOT NULL AND field != "deleted"')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants