Is there a way to update an individual field of a collection

Is there a way to update an individual field of a collection? I see wixData.update updates the whole object (all fields in the selected item). My collection has many fields and I only want to update 1 field based on actions taken in a dynamic item page connected to a different collection.
I tried adding the collection as another dataset in a dynamic item page of a different collection and tried the following code but it didn’t work:

export function checkbox1_change(event, $w) {
// update waves count - subtract 1
// #wavesCount textbox is linked to dataset: #membersDataset1
const waves = parseInt($w(“#wavesCount”).text, 10);
waves = waves - 1;

$w.onReady( () => {
$w(“#membersDataset1”).onReady( () => {
$w(“#membersDataset1”).setFieldValues( {
“waves”: waves
} );

} );

} );

}

setFieldValues is the proper way to do this, as far as I know. However, you also need to add a $w(“#membersDataset1”).save(); to confirm the changes. So you can add it directly to your code or createa separate button that saves.

Thanks! Once I figured out filtering the dataset first, that line of code helped a ton!

Hi All, I’ve managed to build a string “businessCatsChosen” with the content I wish to insert in my database. I’ve tried using the following to save the data:

$w(wixData).onBeforeSave( () => {
$w(wixData).setFieldValue(‘vStoreBuisCat’, businessCatsChosen);
$w(wixData).save();
} );

I’ve tried inserted the lines within

a)
export function SaveCategoriesButton_click(event) {
}

and b)

$w.onReady( function () {
//TODO: write your page related code here…
});

Neither seem to work. I’d really appreciate some hep here.

Thanks!

Riaz

setFieldValues() followed by save(), but how could you use this to update a single field on the entire database? I’ve tried doing it with a for loop and also forEach, but it just stays on the current item/row of the database - can’t find how to move on to the next row/item…

Hey,

You just need to set the field you want to update and save the dataset:

$w (“#myDataset”). setFieldValue (“fieldName”, “fieldValue”);
2 $w (“#myDataset”). save ();

thanks