question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query filter does not work with booleans

See original GitHub issue

Hi,

I have a model with a boolean, for example blogpost.published.

If I query GET /blogposts?published=true, I got nothing because published in the query sent to mongoose is a String, with “true”, instead of being a Boolean true.

How can I query booleans ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dafflcommented, Sep 15, 2016

Another option is to convert the query values in a hook:

app.service('myservice').before({
  find(hook) {
    const query = hook.params.query;

    if(query.published !== undefined) {
      hook.params.query.published = query.published === 'true' ? true : false;
    }
  }
});
1reaction
sylvainlapcommented, Sep 15, 2016

yeah that works, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Elasticsearch boolean query doesn't work with filter
You need to supply minimum_should_match in your first query. I did the following and only got a single document (your desired outcome)
Read more >
Solved: oData filter issue with a boolean field
Solved: I'm trying to use oData filter on IsSaleProcessingStopped field in SalesOrderHeaderV2 and having a hard time making it run. This field is...
Read more >
BOOLEAN column, can't apply filter in Power BI Desktop?
Solved: I have a boolean true/false measure on one of my tables, but I'm having trouble applying a filter on it. Is this...
Read more >
Boolean field filtering does not work when no values are set
The filter is set Restricted access is not equal to TRUE, so it seems to me that NULL values should be included in...
Read more >
Boolean query | Elasticsearch Guide [8.5] | Elastic
The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found