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

Sometimes 'Infinity' is returned in the converted result #28

Closed
vinay-luminar opened this issue Mar 9, 2022 · 4 comments
Closed

Sometimes 'Infinity' is returned in the converted result #28

vinay-luminar opened this issue Mar 9, 2022 · 4 comments
Assignees

Comments

@vinay-luminar
Copy link

vinay-luminar commented Mar 9, 2022

For below example code (example for id 5e8454301455190020332048)

var queryToMongo = require("query-to-mongo")
const {criteria, options} = queryToMongo({ test:'5e8454301455190020332048' });
console.log(criteria)

The returned result is
{test: Infinity}

For any other id for example for some random id 5ed0a62751dbd6008a0e71ec it works fine.
Only for few select ids for which example id 5e8454301455190020332048 shown above the result returned has Infinity.

@pbatey
Copy link
Owner

pbatey commented Mar 9, 2022

Looks like this is related to the way that values are checked as numbers. That sequence is parsable as a number with E notation but resolves to a value too large to represent so is returned as Infinity.

One solution might be to consider strings that resolve to Infinity (or negative Infinity) as strings instead of number.

Looks like I could use Number.isFinite()

@pbatey
Copy link
Owner

pbatey commented Mar 9, 2022

For a workaround, you can wrap the id in quotes to ensure it isn’t interpreted as a Number. Found it in the README:

  • Support for forced string comparison; value in single or double quotes (field='10' or field="10") would force a string compare. Allows for string with embedded comma (field="a,b") and quotes (field="that's all folks").
const {criteria, options} = queryToMongo({ test:'"5e8454301455190020332048"' })

@pbatey pbatey self-assigned this Mar 9, 2022
@pbatey
Copy link
Owner

pbatey commented Mar 10, 2022

Fixed in query-to-mongo@0.10.2

Value resolves to a Number only if (isFinite(value)) - Infinity will no longer occur.

@pbatey pbatey closed this as completed Mar 10, 2022
@vinay-luminar
Copy link
Author

thanks for the fix

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