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
- Error connecting to my GitHub repository
Nothing happens when I try to connect my GitHub repository, but when I try from “Create site,” I get a 500 error.
- Use Limits
I need urgent help, i use appwrite as a chat function for my website and my mobile android application, but recently, for the past 3 months, my database reaches...
- Method EQUAL not wrking in REST API Quer...
Request: ``` postman request 'https://nyc.cloud.appwrite.io/v1/tablesdb/{databaseId}/tables/{tableId}/rows?queries[]={%22method%22%3A%22select%22%2C%22values%2...