Skip to content

how to set schema for array of objects #127

Answered by appy-one
ahdat81 asked this question in Q&A
Discussion options

You must be logged in to vote

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 every message to have the value "string" instead of being of type string. Remove the quotes around string and you are good to go:

await db.schema.set('chats/$chatid',{
  id: 'string',
  messages:'{ message: string }[]' // No quotes around `string` type definition
})

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@ahdat81
Comment options

Answer selected by ahdat81
Comment options

You must be logged in to vote
2 replies
@ahdat81
Comment options

@appy-one
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants