allen
allenβ€’2y ago

Query optional field on schema

I am looking to query an optional field with .eq('fieldName', undefined), however, I am getting the error: [Error: Uncaught Error: undefined is not a valid Convex value. To learn about Convex's supported types, see https://docs.convex.dev/using/types. The provided docs say to use null but that then breaks generated types from optional fields, as the available options are number | undefined. I could refactor this into a union of a number or a null value, but figured I'd ask first as it seems like it should be possible to query an optional field directly.
4 Replies
lee
leeβ€’2y ago
Sorry about that. This is a known issue that will be fixed in 0.13.0. For now i think you should use null and cast it null as number, but in 0.13.0 you would (and should) use undefined To clarify, i recommend updating the filter expression, not the documents or the schema. And you can either cast or @ts-ignore , up to you πŸ™‚
allen
allenOPβ€’2y ago
got it. thanks for the direction
lee
leeβ€’2y ago
0.13.0 has shipped, so i recommend you upgrade. the existing flow using null will stop working on may 15. see "Querying for documents missing a field" in https://blog.convex.dev/announcing-convex-0-13-0/ for more details, and let us know if you have any concerns
The Convex Blog
Announcing Convex 0.13.0
Convex 0.13.0 is here and it’s kinda a big deal. There are some big changes to function arguments and actions.
ian
ianβ€’2y ago
just for clarity, you'll still be able to query for missing fields, but starting 5/15 you'll have to pass in undefined explicitly. null will only fetch fields that are null.

Did you find this page helpful?