Hi everyone,
In my website, after update function, it is returning (console.log) an error - TypeError: Error.captureStackTrace is not a function.
Here’s my code -
You’re updating an item without providing the ID of the item, to really understand what the update process is, you need to know that updating, is actually replacing, that means the old items will be replaced the new items, so when updating as you do, you’re deleting the old data and replacing them with hte new values that you’ve provided, but even this won’t work because you’re not providing the ID (_id) of the items that needs to be updated, it’s always recommended to get the item first, then modify the necessary fields and then update it, for example …
If you want to update a student’s last name, you need to get their details first with a query, then modify the last name, then save the changes with an update.
let student = {};
student.details = await wixData.query('students').eq('id',id).find()
.then((result) => {
let item = result.items[0];
/* Now we have the item/student details, let's
modify it as we want. */
// Here we've modified the item.
item.last_name = "Family";
// Now we'll update the whole item.
return wixData.update('students', item);
})
Notice that we’ve updated the whole item, which means that we’ve submitted all the properties of the item including the one we modified.