Is there a way to query my db where a field is not...
# orm-help

Question

Is there a way to filter by null in Prisma1?

Answer

To filter by not null, you can wrap the field in `not: {}` like `{ where: { not: { endedAt: null } }`. To filter by null specifically, you can use `{ where: { endedAt: null } }`. If you are using `prisma-binding`, you can call `db.post.findMany({where:{category: {not: null}}})`.

s
Is there a way to query my db where a field is not null? like db.post.findMany({where{category !null}}) or something?
a
Wrap it in
not: {}
o
i.e.
db.post.findMany({where:{category: {not: null}}})
s
Great thanks!
j
Lol, just asked the same question. Where is the
findMany
function coming from?
Copy code
const existingMatches = await prisma.query.matches(
  {
    where: { endedAt: { not: null } },
  },
  info,
)
This throws an error:
GraphQL error: Variable '$_v0_where' expected value of type 'MatchWhereInput' but got: {"endedAt":{"not":null}}. Reason: 'endedAt' Date value expected
a
try
Copy code
{ where: { not: { endedAt: null } }
j
Same issue, I'm guessing I need to do something like
NOT: []
if I needed where it's not null. My issue is I can't filter by
null
at all
I'm using
prisma
from
prisma-binding
, passed in through the context in the resolver. Perhaps the issue is that I'm not using
db
, but i'm also not sure where that's coming from
r
Hey @Joseph 👋 Are you using Prisma1?
j
Hey @Ryan, sure am 🙂
@Ryan Is there a way to filter by null in Prisma1?
455 Views