Hi!
How can I append new data to an array?
- I have a
Create
API Route that creates posts. - I would like the user to be able to append data to already existing Records.
- I believe that I need to use
Append
, but I’m receiving an error:"Append function requires 2 argument(s) but 1 were given"
.
This is the structure of the Record in FaunaDB:
{
miscFields: ""
...
Posts: [
{
text: ""
image: ""
},
]
}
// I want to update Posts with a new post
The new post content is generated on the front-end and passing to a new API Route, which is described below:
// id refers to the record in question, and finds the correct record to be updated
const dbs = await client.query(
q.Update(q.Ref(q.Collection('collection'), id), {
data: {
Posts: q.Append({
text: postText,
image: imageURL,
})
}
})
)
...
}
This was one of my attempts and throws an error because the data to be appended to isn’t specified, but I’m not sure how to exactly to describe it.
Any pointers would be much appreciated!