Underscores not allowed at start of nested fields
We've run into this issue when storing some data inside v.any() fields. This is a blocker for us cause we have to store changes of our customer's schema in Convex so it would be great to have this limit removed.
If I'm missing something please let me know!
5 Replies
It's in the doc under limits, https://docs.convex.dev/production/state/limits its for system fields. I've seen it in multiple sample projects where they almost always serialize the objects removing the underscore. If you want to store a nested _id its generally suggested you create your own id anyway. Or at least rename it. Because you cant insert the original _id back in anyway.
Limits | Convex Developer Hub
We’d love for you to have unlimited joy building on Convex but engineering
wait here it says field names can start with an underscore?
That's a mistake. The section above it says that you can't, and you actually just can't as you have noticed. It's there to reserve the space for their own future system fields.
I get that you're working pretty directly with your customer's javascript data so it would feel natural to do this, but you're letting external user JSON directly define your database's shape. Remember that you can index directly on these nested keys.
If you are really committed to doing this for some reason, you need to take control of the object's keys, and define your own fields.
But it's actually less work to it the right way and just JSON.stringify.
right, JSON.stringify is probably the best in this case
hey, I'll take a look at fixing the docs. we also have been considering removing this restriction for nested fields -- we'd still disallow fields that start with an underscore at the top-level, since we need to reserve that for system fields, but any other field could start with an underscore.