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

Filtering string fields will not work when filter value consists of numbers #71

Open
Halt001 opened this issue Aug 9, 2017 · 2 comments
Assignees

Comments

@Halt001
Copy link

Halt001 commented Aug 9, 2017

qs.parse({"foo":">1"}) results in {"foo":{"$gt":1}} and not {"foo":{"$gt":"1"}} where the '1' is converted to a Number field automatically. If the foo field is a string field in the database than this search query will find nothing.

I haven't tested it but this will probably also be true for booleans. So you probably can't filter a text field on the word 'true'.

There should be a way to force the creation of a string filter for values that could also be a number or a boolean.

@Starefossen
Copy link
Contributor

That is correct behaviour with the default settings. You can turn off automatic parsing of Numbers and Booleans by setting toNumber and toBoolean respectively to false like this:

const qs = new MongoQS({
  string: {
    toNumber: false,
    toBoolean: false,
  }
});

@Halt001
Copy link
Author

Halt001 commented Aug 21, 2017

Sorry fo the late reply.
This doesn't help the situation where you want to combine a filter on a number field and a string field like this:
qs.parse({"fooString":">1", "fooNumber":">1"}); where you expect:
{"fooString":{"$gt":"1"}, "fooNumber":{"$gt":1}}

Maybe it would help if you add single quotes to the syntax to aid in discriminating string fields from number fields. Like this:
qs.parse({"fooString":">'1'", "fooNumber":">1"}); This may need to be escaped on the url though.

@Starefossen Starefossen self-assigned this Aug 21, 2017
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

No branches or pull requests

2 participants