13

I'm trying a query on a postgres database through the loopback api explorer:

{"where": {"archived_at":{ "neq": null }}}

However, I only get results where archived_at is null?

Jordan Kasper
  • 12,144
  • 3
  • 33
  • 52
Bunker
  • 978
  • 3
  • 10
  • 25
  • 1
    I'm not sure if checking for NULLs is implemented, there has been some discussion about this (isSet operator). If internally this is translated into `archived_at = NULL` then it won't work, since NULL is not equal to even NULL. – Sami Kuhmonen May 15 '15 at 15:41
  • 1
    This doesn't answer the question but it might help. I'm using mongodb, and I get the same results from the query in your question, i.e. it contains records where the field is `null` but not records where the field is non-`null` (which is the opposite of what the query looks like it should give). I also get the same if I use `{"where":{"archived_at":{}}}`. But `{"where":{"archived_at":{"neq":{}}}}` gives me everything, unfiltered. I'd love to know the answer to this, surely getting all records with a non-`null` value in a given field is a common use case. – leftclickben May 15 '15 at 15:51

2 Answers2

14

The following query worked for me...

{ "include": [ "currency" ], "where": { "currencyCode": { "neq":  null } } }

I was requesting tables that had a currencyCode...

(Sorry for the poor quality of my response, I just wanted to share, even I didn't have a straight answer to the OG's question, and I don't have enough props to comment)

Bacteria
  • 7,810
  • 10
  • 47
  • 61
1

It depends on the database. Based on postgresql in loopback 3.

For search integer / number null or not null value.

I think it depends on the database and loopback version.

  1. You can try like nlike query in loopback (but how to use it depends on the db) https://loopback.io/doc/en/lb3/Where-filter.html#ilike-and-nilike

  2. Querying not null value

    Explorer:

    {"where": {"principalId": { "neq": "" }} }
    

    or in server

    {where: {"principalId": { neq: "" }} }
    
  3. Try to direct query in database. Loopback allowed for that.

    "angular": "^1.6.3",
    "angular-messages": "^1.6.3",
    "angular-ui-validate": "^1.2.2",
    "async": "^2.1.5",
    "bower": "^1.8.0",
    "compression": "^1.6.2",
    "cors": "^2.8.1",
    "helmet": "^3.5.0",
    

"loopback": "^3.7.0",

"loopback-boot": "^2.23.0",
"loopback-component-explorer": "^4.2.0",
"

loopback-component-storage": "^3.2.0",

"loopback-connector-mongodb": "^3.0.1",
"loopback-connector-mysql": "^3.0.0",
"loopback-connector-postgresql": "^2.8.0",
"loopback-console": "^1.1.0",
"loopback-datasource-juggler": "^3.5.0",
"loopback-sdk-angular-cli": "^3.0.0",
"milligram": "^1.3.0",
"serve-favicon": "^2.4.2",
"strong-error-handler": "^2.0.0"
marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388