Support additional string/primitive query values
-
true -
false -
null -
"true" -
"false" -
"null"
These are all valid JSON values, but can't all be queried at present. Right now, true and false are being cast to their primitive types when supplied as string queries (and null is not):
q=booleanField1:true,booleanField2:false
https://github.com/vasanthv/jsonbox/blob/6781bd24a2e292fe3ea2cd33c76a52d99f801b99/src/helper.js#L84-L85
I think it might be better to treat these non-string primitive values the way that numbers are being treated, but as special cases:
q=booleanField1:=true,booleanField2:=false,fieldWithNoValue:=null
https://github.com/vasanthv/jsonbox/blob/6781bd24a2e292fe3ea2cd33c76a52d99f801b99/src/helper.js#L71
I haven't worked with mongo in a long time, so I'm not sure about the exact syntax, but something like
else if (value.startsWith('=')) {
if (val === 'true') query['data.' + key] = true;
else if (val === 'false') query['data.' + key] = false;
else if (val === 'null') query['data.' + key] = null;
else query['data.' + key] = +val;
}
and then you could just remove the code from lines 84–85 above.
I think you might be able to implement the conditional primitive matching now, without breaking changes, but allowing for string matching of "true" and "false" would be a breaking change for the next major version.