I'm trying to update the data which has been stored on a Collection in ENUM Type. I using the user id as document id during it's creation. I have no issues while creating and deleting it, but I'm facing issues when i tried to update the values.
This is the structure of data which has been stored,
{
profile: {
links: {
github: "xxx",
linkedin: "xxxx",
},
about: "",
points: 0,
courseStats: {},
},
}
This is how i tried to update the document,
const updateUserData = async (
fieldToUpdate,
dataToUpdate,
isNested = false,
fieldToInsert
) => {
try {
// Update document
const updatedDocument = await databases.updateDocument(
"DOCUMENT-ID",
"COLLECTION-ID",
user.$id, // Acts as DOCUMENT-ID
isNested
? {
profile: {
...userData,
[fieldToUpdate]: {
...userData[fieldToUpdate],
[fieldToInsert]: dataToUpdate,
},
},
}
: {
profile: {
...userData,
[fieldToUpdate]: dataToUpdate,
},
}
);
// Update state with the new document data
setUserData(updatedDocument.profile);
} catch (error) {
console.error("Error updating document:", error);
}
};
After this function's execution, the backend only returns this error,
Error updating document: [AppwriteException: Invalid document structure: Attribute "profile" has invalid format. Value must be one of (links, about, points, courseStats)]
Uhh you can't nest data like that with an enum attribute...would you please share your collection as JSON? If you inspect the network logs in your browser while viewing the loading the collection in the Console, there should be an API call for the collection
Recommended threads
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...