Deeply nested documents
I discovered today that there is a limit on object depth in Convex of 16—I see that this is documented here (https://docs.convex.dev/using/types#limits), but it could also be nice to write a note in the description of the
Object
Convex type in the Convex Types table here (https://docs.convex.dev/using/types#convex-types) (I don't think I would have missed it if it were there).
Is there any chance this limit might be changed in the future? I ran into this with an extremely small document by trying to store a ProseMirror doc serialized as JSON. I can just serialize it as a string and everything should be fine, but (naively, with no technical knowledge of why the limit is in place) I did find it surprisingly small.2 Replies
Hi! This is related to the fact that JSON documents are not just opaque objects to convex, convex runs all sort of type inference and type tracking on them, and deeply nested documents can create some potential algorithmic complexity issues around our type management
so, short term solution and long term possible solution...
short term, yep! make it a string. you're right, this is not ideal, but is the easiest way to unblock you for now. longer term, we're considering introducing a JSON value type which would be an opaque subtree from convex's perspective, similar to other database systems's JSON type. it can't be typechecked / indexed etc, but it saves you from writing boiler plate that serializes / deserializes stuff and has better ergonomics
Thanks Jamie! This constraint makes more sense to me now. I definitely think a JSON value type like the one you describe would be nice. I think that this constraint was perhaps particularly surprising because I was defining this field in my schema as
s.any()
, which felt semantically like a value which should be opaque to Convex in the ways I'd apparently like it to be.
Anyways, I'll revert to storing it as a string for now 🧵