Loopback neq: null
Asked Answered
Y

3

15

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?

Yama answered 15/5, 2015 at 15:30 Comment(2)
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.Rapper
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.Giule
F
16

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)

Finial answered 23/8, 2015 at 14:5 Comment(1)
I have same issue. i am missing ("") in neq. As in documentation they do not use ("") for other operators.Tifanytiff
E
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"
Elwina answered 1/5, 2017 at 21:41 Comment(0)
G
0

You need to cast it as unknown and then cast it back.

      const filter = {...};
      const whereSoftDeleted = <Condition<T>>(<unknown>{
        archivedAt: {neq: null},
      });
      const newFilter = {
        ...filter,
        where: {...filter.where, ...whereSoftDeleted},
      });
Goldin answered 22/4 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.