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
- Type 'Theme' does not satisfy the constr...
Type 'Theme' does not satisfy the constraint 'Row'. Type 'Theme' is missing the following properties from type 'Row': $id, $sequence, $tableId, $databaseId, a...
- Custom Domain TLS Error (perfinso.com)
Hey Appwrite team/community, I need urgent help with a custom domain setup! I've added perfinso.com to my project, pointed the nameservers, and verification is...
- Is there any reason you cant use a manag...
So quick context I would like to host a selfhosted Appwrite instance and I personally prefer to use managed DBs when able and really like to keep my DBs on dedi...