-
Here's a simple example: await db.schema.set('chats/$chatid',{ so now i want to add a message object to the messages array, via proxy chat.messages.push({ and im getting the error: "Failed to update server value for "...", rolling back cache to previous value. Error: Error: Schema validation failed: every array value of path "..." must match one of the specified types" I've tried various different syntaxes and whatnot, this seems to be the most correct. but cant seem to get it to work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Although I would recommend not using arrays of objects (use object collections instead!), the error is in your schema definition. By setting await db.schema.set('chats/$chatid',{
id: 'string',
messages:'{ message: string }[]' // No quotes around `string` type definition
}) |
Beta Was this translation helpful? Give feedback.
-
Sidenote about why not to use arrays: see Using arrays Additional info about using arrays with a live data proxy: any change to any item in the array will cause the entire array to be rewritten because of reasons described in above link. If you use object collections instead, only the actual changes are written and synced. To change your code to use object collections instead, change your schema to: await db.schema.set('chats/$chatid',{
id: 'string',
messages: {
'*': { message: 'string' }
}
}); Of course you will then have to set the initial value of a chat.messages to Your chat.messages.push({ message: 'Hello' }); // stored in eg "[chat path]/messages/l5f4ll26000109mh76lma34d" |
Beta Was this translation helpful? Give feedback.
Although I would recommend not using arrays of objects (use object collections instead!), the error is in your schema definition.
By setting
messages
to{message: "string"}[]
you are enforcing everymessage
to have the value"string"
instead of being of typestring
. Remove the quotes around string and you are good to go: