#community-help

Handling `string | null` Fields in Schema

TLDR gab asked about handling string | null fields in schemas. Kishore Nallan suggested they could be marked as optional, so either the field doesn't exist or the value can be null.

Powered by Struct AI
5
31mo
Solved
Join the chat
Jul 09, 2021 (31 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
03:55 PM
Hi, how should be handled fields that can be string | null ?
Shall I create a schema with string type and then play with the dirty_values flag to handle null values?
Or shall I just drop my empty fields maybe?
Thanks for insight
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:56 PM
You can mark field as optional: true in the schema
03:56
Kishore Nallan
03:56 PM
This way, either that field need not exist in the document or its value can be null (the latter feature available in the RC)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
03:57 PM
Ups sorry to have badly read the documentation, it makes sense, thanks!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:57 PM
No worries.