TypeError: Error.captureStackTrace is not a function

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 -

export function submit_click(event) {
  $w('#upload').startUpload()
  .then( (uploadedFile) => {
         $w('#photo').src = uploadedFile.url;

let user = wixUsers.currentUser;
let userId = user.id;

let toUpdate = {
 "fullName":      $w('#fullName').value,
 "email":        $w('#email').text,
 "profilePhoto":   $w('#photo').src,
 "userId":    userId
};

wixData.update("UserProfileData", toUpdate)
  .then( (results) => {
 let item = results; 
    $w('#errorGood').show();
    $w('#errorGood').text = "Updated !!!";
    $w('#fullName').value = "";
  } )
  .catch( (err) => {
    $w('#errorGood').show();
 let errorMsg = err;
    console.log(errorMsg);
    $w('#errorGood').text = "Error";
  } );

  } )

}

Thanks,
Ajith

Hi @ajithkrr

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.

Hope this helps~!
Ahmad

Hai Ahmad,
Thanks It worked

Here’s my code –

import wixData from 'wix-data';
import wixUsers from 'wix-users';

$w.onReady(function () {
let user = wixUsers.currentUser;
let userId = user.id;
console.log(userId);


wixData.query("UserProfileData")
  .eq("userId", userId)
  .find()
  .then( (results) => {
 if(results.items.length > 0) {
 let item = results.items[0];
 let itememail = results.items[0].email;
      $w('#email').text = itememail;



$w('#submit').onClick(function () { 
  $w('#upload').startUpload()
  .then( (uploadedFile) => {
         $w('#photo').src = uploadedFile.url;

  item.fullName = $w('#fullName').value;
  item.profilePhoto = $w('#photo').src; 

wixData.update('UserProfileData', item)
.then((resuls1) => {
 console.log("Submitted");
 $w('#errorGood').show();
 $w('#errorGood').text = "Updated !!";
})
.catch( (error) => {
 let errorMsg = error.message;
 let code = error.code;
    console.log(errorMsg);
    $w('#errorGood').show();
    $w('#errorGood').text = "Error. Please Retry !!";

  } );


  } )
})
      }
 else{ 
        console.log("Nothing");
      }
  })
});


Thanks Once Again !!
Can you (please) check here !! →

@ajithkrr OK