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
- Auto Updating Backend & Auth via Appwrit...
<@870607367597850624> Hey everyone 👋 I wanted to ask to ask for a friend, he’s asking if Appwrite be used in a similar way to Supabase when integrated with AI ...
- execution failed
When executing an appwrite function, I'm getting a 500 error, but I don't see it in executions. This issue appeared today. Here's the appwrite function ID: 68b4...
- Is Database Operators available in Cloud...
Is it possible to do the above?