let users update dataset: update()

Good afternoon and apologies,
I’m using the update() api to let users update their user form.

Content is stored in a database named “EV owner Database”. Content (to be updated) in the database is “EV” and “Location”.

The code, from my limited understanding, should be ok. However, with each and every submit, a new line is written into the database. I added my understanding in the code notes. Could anyone give me some guidance which direction I should seek to fix that error? The code simply has no impact in my page.

import wixData from 'wix-data';

wixData.query("EVownerDatabase")           //name of database
.eq("Owner", "00001")                     //owner submitted data??
.find()                                   //if yes...
.then( (results) => {                     //then go to his results

if(results.items.length > 0) {            //and if owner entered value 
let item = results.items[0];
item.EV = "Tesla";                        //update item, e.g. EV
item.Location ="Kiel";
wixData.update("EVownerDatabase", item);

} else {
                 // perform default, if owner not found (create new data)
}
} )
.catch( (err) => {
let errorMsg = err;
} );

Hello.

I can see that the item field keys you are querying or updating in your code is capitalized. Try checking field keys for ‘Owner’, ‘Ev’ and ‘Location’ fields since they usually start with a small letter by default and this is best practice.

You can refer to the examples in the API here .

Good luck!

@samuele many thanks for your reply. Yes, you’re right - totally missed that capitalization. Unfortunately the code still writes a new entry, although the user exists. Is there any other area I can look at?
Many thanks & best wishes,
Constantin