Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.
This repository was archived by the owner on May 25, 2023. It is now read-only.

Support additional string/primitive query values #53

@jsejcksn

Description

@jsejcksn
  • 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

jsonbox/src/helper.js

Lines 84 to 85 in 6781bd2

if (value == 'true') query['data.' + key] = true;
else if (value == 'false') query['data.' + key] = false;

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

else if (value.startsWith('=')) query['data.' + key] = +val;

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions