RJ
RJ2y ago

Filter by unset

It would be nice if there were a way to filter by a field whose value is "unset". Given that I can now use db.patch to unset a field's value by passing in undefined (e.g. db.patch(id, { tag: undefined }), per the docs)—which is really nice!—I also expected something like
.filter((q) =>
q.eq(q.field("tag"), q.not(undefined)),
)
.filter((q) =>
q.eq(q.field("tag"), q.not(undefined)),
)
to work, but it doesn't!
typescript: Argument of type 'undefined' is not assignable to parameter of type 'ExpressionOrValue<boolean>'.
typescript: Argument of type 'undefined' is not assignable to parameter of type 'ExpressionOrValue<boolean>'.
3 Replies
RJ
RJOP2y ago
Actually, it's occurring to me that perhaps I'm not using q.not correctly!
lee
lee2y ago
q.neq(q.field("tag"), undefined) should work 🙂 Or if you prefer, q.not(q.eq(q.field("tag"), undefined))
RJ
RJOP2y ago
I didn't realize that there was a q.neq! I used q.not(q.eq(...)) and that worked. Thank you @lee!

Did you find this page helpful?