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

Using $gt and $lt together #20

Closed
leobudima opened this issue Apr 7, 2016 · 2 comments
Closed

Using $gt and $lt together #20

leobudima opened this issue Apr 7, 2016 · 2 comments
Assignees

Comments

@leobudima
Copy link

Hi,

thanks a lot for your effort on this library - extremely useful!

I'm having a problem, though, when using it to parse query params sent to a hapijs server and trying to specify a range of values for a parameter, such as:

url?count=>10&count=<100

parsed query comes out as:

count: { '$in': [ '>10', '<100' ] } }

The expected result would, naturally, be:

count: {$gt: 10, $lt: 100}

Do you have any suggestions on how to work around this, or is this something you would consider supporting?

Thanks!

@Starefossen Starefossen self-assigned this Apr 7, 2016
Starefossen pushed a commit that referenced this issue Apr 7, 2016
Refacotr operator parsing logic into a separate function which is
reused for arrays and normal key value parsing. This also allows
multiple entries of operators in adition to $in and $nin operators
inside arrays.

The query `?count=>10&count<100` will evaluate to the following:

```
{
  "count": {
    "$gt": 10,
    "$lt": 100,
  }
}
```

BREAKING CHANGE: the new parser will not discriminate agains having
both $in and $nin values for the same key - which is redundant - but
still a valid query.

Close #20
Starefossen pushed a commit that referenced this issue Apr 7, 2016
Refacotr operator parsing logic into a separate function which is
reused for arrays and normal key value parsing. This also allows
multiple entries of operators in adition to $in and $nin operators
inside arrays.

The query `?count=>10&count<100` will evaluate to the following:

```
{
  "count": {
    "$gt": 10,
    "$lt": 100,
  }
}
```

BREAKING CHANGE: the new parser will not discriminate agains having
both $in and $nin values for the same key - which is redundant - but
still a valid query.

Close #20

Signed-off-by: Hans Kristian Flaatten <hans.kristian.flaatten@dnt.no>
Starefossen pushed a commit that referenced this issue Apr 7, 2016
Refactor operator parsing logic into a separate function which is
reused for arrays and normal key value parsing. This also allows
multiple entries of operators in addition to `$in` and `$nin`
operators inside arrays.

The query `?count=>10&count<100` will evaluate to the following:

```
{
  "count": {
    "$gt": 10,
    "$lt": 100,
  }
}
```

BREAKING CHANGE: the new parser will not discriminate agains having
both `$in` and `$nin` values for the same key - which is redundant -
but still a valid query.

Close #20

Signed-off-by: Hans Kristian Flaatten <hans.kristian.flaatten@dnt.no>
@Starefossen
Copy link
Contributor

You suggestion has been implemented in mongo-querystring@3.0.0. Check it out and thanks for using this library 😄

@leobudima
Copy link
Author

Thanks so much, made my day! :) All the best!

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

No branches or pull requests

2 participants