Field name +1 must only contain alphanumeric characters or underscores and can't start with a number
I'm getting the above error when I try to save a new record, but I'm a little unsure why it would happen. I've tried thinking through a few things, but I'm still not too sure how to proceed. Are there any tips for debugging this error?
10 Replies
Does this thread help? https://discord.com/channels/1019350475847499849/1100142672020246559
It sounds like you have an object with a key called “+1” which isn’t supported currently without using a Map
Thanks! I can try making a Map instead -- I haven't thought of that will follow here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) . I guess one thing that I'm a little confused on though is that I try to save the JSON objects as strings (I have other similar tables to this one w/ same pattern). I was hoping this would be sufficient to avoid the above error, but it sounds like I'm not understanding it correctly?
Map - JavaScript | MDN
The Map object holds key-value pairs and remembers the original insertion
order of the keys. Any value (both objects and
primitive values) may be used as
either a key or a value.
The values can be json strings, and the keys are strings, but we add extra constraints on the keys of objects (for now)
ah okay thanks
okay doing {data: new Map(Object.entries(flat_record))} worked for me - thanks for the tip! Also it was probably implied in the above post, but if anyone else runs into this -- you will still get errors if you map a nested json. this post had a flatten function (https://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-javascript-objects). Haven't checked correctness to much but worked for me to at least save data relatively quickly.
Stack Overflow
Fastest way to flatten / un-flatten nested JavaScript objects
I threw some code together to flatten and un-flatten complex/nested JavaScript objects. It works, but it's a bit slow (triggers the 'long script' warning).
For the flattened names I want ".&qu...
@Joe with 0.19.0 you can now store arbitrary strings as keys - you don't have to use Map anymore. In fact, we've gotten rid of Map. Sorry for the thrash on your end - we're getting close to 1.0 so things should be more stable from now on
@ian If we upgrade to 0.19.0, we're able to store any arbitrary string keys correct?
Yes, on nested documents. The top-level document fields still have restrictions like not starting with
_
to not collide with _id
and future system fields. But you can store arbitrary JSON data under a v.any()
field
Though if you're going to 0.19 you may as well go all the way to 1.0: they're essentially the sameActually there are still limits on all field names:
The field name format allows any non-control ASCII characters, has maximum length of 1024 characters and cannot begin with $ (to avoid ambiguity with our serialization protocol).
From our release notes: https://news.convex.dev/announcing-convex-0-19-0/
Convex News
Announcing Convex 0.19.0
Convex 0.19.0 has been released! This release includes changes foreshadowed in our last release and constitutes our first 1.0 release candidate.
The main updates in 0.19.0 are:
* Objects keys in the database and in function input/output can be most strings
* Support for Maps and
Sounds good thanks. Still getting an error for nested fields starting with
_