[SOLVED] Invalid document structure: Unknown attribute: "$collectionId"
- 1
- Resolved
- Functions
- Web
Hi, I got this error on Appwrite Function, but can't found any solution on google:
module.exports = async (req, res) => {
const database = new sdk.Databases(client);
const currentOrder = JSON.parse(req.variables.APPWRITE_FUNCTION_EVENT_DATA);
const res1 = await database.updateDocument(
currentOrder.$databaseId,
currentOrder.$collectionId,
currentOrder.$id,
currentOrder,
[
sdk.Permission.read(
sdk.Role.user(req.variables.APPWRITE_FUNCTION_USER_ID)
),
sdk.Permission.update(sdk.Role.team("admin")),
]
);
}
Hi there 👋 allow me to look into this and get back to you
hope to see your response soon 😄
So collectionId should not be in currentOrder, only in parameter should be fine
But when I console.log(currentOrder.$collectionId), it show correct collection id
Please help me @joeyouss
Hi @huylv , just DMed you
still need help 😦
Hey there 👋 Problem here seems to be that event give you whole order document, but updateDocument doesn't like that you provide all those attributes in the document. In the end, update endpoint only needs stuff that you want to update.
Soo solution here should be to pass new currentOrder as third parameter, and make it only have data that you want to update.
Tho I think this should work - this might be bug with payload of specific event. Ill take a look to double check.
Indeed, I am getting same error when trying to reproduce. This code fails:
editHabitName: async (habit: Habit, newName: string) => {
habit.name = newName;
return await databases.updateDocument<Habit>('main', 'habits', habit.$id, habit);
},
This code works:
editHabitName: async (habitId: string, name: string) => {
return await databases.updateDocument<Habit>('main', 'habits', habitId, {
name
});
},
When doing updateDocument, make sure to pass data object that only has stuff you want to change. In my scenario, the name attribute.
@Meldiron Thanks, I have done it. Just pass empty object to the third parameter and only update the permission. Appwrite is really awesome, but error logs from appwrite's functions are not good. Hope you guys improve it 😄
Eyyy glad you solved it ✨
cc @VincentGe regarding dev-experience with errors
[SOLVED] Invalid document structure: Unknown attribute: "$collectionId"
Ooof this is a hard one. 👀 We can probably write these better for the update/create endpoints though.
Related issue: https://github.com/appwrite/appwrite/issues/4802
Recommended threads
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- How can I disable client-side account re...
Hi everyone! I’m currently building a game backend using Appwrite, and I’d like to prevent users from creating new accounts directly through the client. My go...
- relationships bug or error idk
hey every one, am using am using appwrite on a project and ran into a problem where by created a relationship and two way to be specific and it is stuck on proc...