TwendyKirn
TwendyKirn•10mo ago

Set dynamic key in v.object inside database schema

Hello, is it possible to set a dynamic object key inside the schema? Use case: I have an object which stores metada of each element, it looks like { [elementId: string]: {....some data} }
6 Replies
Michal Srb
Michal Srb•10mo ago
Hey, not yet, we'll likely add a v.record for this in the future. For now the best work around is: v.array(v.object({key: string, value: ....})) or use v.any() and rely on TypeScript for now.
TwendyKirn
TwendyKirnOP•10mo ago
Thank you! Gonna try 🙂
Son
Son•5mo ago
looking forward to v.record @Michal Srb
ballingt
ballingt•5mo ago
we hear you! I want this too
v
v•4mo ago
me too, but just because i think its cool lol
lee
lee•3mo ago
for anyone finding this thread, v.record exists now https://docs.convex.dev/database/schemas#record-objects
Schemas | Convex Developer Hub
Schema validation keeps your Convex data neat and tidy. It also gives you end-to-end TypeScript type safety!

Did you find this page helpful?