Database not updating

I have been banging my head against the proverbial wall for a while now and I’m hoping someone here can help. I have (what I believe) is a rather simply page. The page should check for a user’s record in a database, if it doesn’t exist it’ll add the user to the database. That part works and I’m doing that with the following method:

let userEmail = currentMember . getMember (). then (( member ) => {

      **let**  userEmail  =  member.loginEmail ; 
      console . log ( "userEmail function: "  +  userEmail ) 
      **return**  member.loginEmail ; 
      
  }) 

. then (( userEmail ) => {
wixData . query ( “selfTapeMayParticipantData” )
. eq ( “email” , userEmail )
. find ()
. then (( res ) => {
console . log ( "res.length: " + res.length )
if ( res.length == 0 ) {
let toInsert = {
“email” : userEmail
};
wixData . insert ( “selfTapeMayParticipantData” , toInsert )
. then (( userEmail ) => {
$w ( “#dataLocalSelfTapeMayParticipantData” ). setFilter ( wixData . filter (). eq ( “email” , userEmail ));

      **let**  profItem  =  $w ( '#dataLocalSelfTapeMayParticipantData' ). getCurrentItem (); 

    }) 
  }  **else**  { 
      $w ( "#dataLocalSelfTapeMayParticipantData" ). setFilter ( wixData . filter (). eq ( "email" ,  userEmail )); 
      **let**  profItem  =  $w ( '#dataLocalSelfTapeMayParticipantData' ). getCurrentItem (); 
  } 
  }) 

})

The next step is to UPDATE the existing record with data captured on the page. I am choosing to do this via code because I want more flexibility down the road. Here is the code I am attempting to leverage and it simply won’t work. I have been fiddling around with different permutations and sometimes the _updatedDate record will update, but no data will show up in the expected now. Other times I get an error of some sort. Any guidance or help would be much appreciated.

export function saveData ( itemID ){
let userEmail = currentMember . getMember (). then (( member ) => {
return member.loginEmail ;

  }) 

let instagramHandle = $w ( ‘#inputInstagram’ ). value
//console.log("instagramHandle " + instagramHandle)

console . log ( "instagramHandle value " + instagramHandle )
console . log ( "itemID: " + itemID )
/—OPTION #1/
wixData . get ( “selfTapeMayParticipantData” , itemID )
. then (( item ) => {
// Update the instagram field of the item
item.instagram = instagramHandle ;
console . log ( "item.instagram: " + item.instagram )
// Save the updated item to the database
return item.save ;
})
. then (() => {
console . log ( "Item " + itemID + " updated successfully with value: " + instagramHandle );
})
. catch (( err ) => {
console . log ( "Failed to update item: " + err );
});

/*****OPTION #2 */ 

wixData . get ( “selfTapeMayParticipantData” , itemID )
. then ( dataCollection => {
let dataToSave = ({
“instagram” : instagramHandle
})
console . log ( “----dataToSave—” )
console . log ( dataToSave )
console . log ( “---------------” )
dataCollection . update ( dataToSave )
console . log ( “----dataCollection—” )
console . log ( dataCollection )
console . log ( “---------------” )
return dataCollection.save ;
})
/*****END OPTION #2/
}

I see that after you get your item using wix data, you are not then using .save() properly (you can’t return item.save - it’s not doing anything) but I also think you may mean to use .update()

Regardless, take a look at the API documentation, after you get your item you will want to call a function that then completes your update or save

https://www.wix.com/velo/reference/wix-data/update

Thank you for the response AmandaM. I figured out what happened (not surprisingly, you were correct). However, my issue was more fundamental than that. I am using GCP BigQuery as the back-end database and I was running into streaming buffer cache conflicts. I fixed my issue by creating a view of my data that pulls in a unique row and switched to an append(insert) in the actual table each time the user changes a value. This addressed my issue.

Ahhhh, yes that does change things. So glad you got it working and happy to help.