Skip to main content

updateMany()

Updates all rows matching the specified conditions to the given values.

Available Keys​

KeyDescriptionOptionalNotes
whereSpecifies update conditionsOptionalTargets all rows if omitted
dataData to updateRequired
limitMaximum number of records to updateOptionalNegative values cause an error
note

data is required. Omitting it throws GassmaMissingArgumentError (message: Argument data is missing.). where is optional; if omitted, all rows are targeted. The same applies to where: {} and to a where that became empty because its conditions were all undefined.

Fields whose data value is undefined are treated as "not specified" and are not updated.

Example Sheet​

Example Sheet

Description​

Suppose you want to perform the following operation on the above example:

  • age => Change 20 to 21

The code would be:

const gassma = new GassmaClient();

// gassma.{{TARGET_SHEET_NAME}}.updateMany
const result = gassma.sheet1.updateMany({
where: {
age: 20,
},
data: {
age: 21,
},
});

The return value has the following format:

{
count: 1;
}

The number of updated rows is returned.

The where specification follows findMany().

limit​

You can specify the maximum number of records to update:

// Update at most 2 records
const result = gassma.sheet1.updateMany({
where: {
pref: "Tokyo",
},
data: {
age: 99,
},
limit: 2,
});

Specifying limit: 0 results in 0 updates (nothing is updated).

caution

Specifying a finite negative value for limit throws GassmaLimitNegativeError.

NaN / Infinity / -Infinity / null throw GassmaInvalidValueError instead. In that case no rows are updated at all.

gassma.sheet1.updateMany({ data: { age: 1 }, limit: NaN });
// => Invalid value for argument `limit`. Expected a finite number, but received NaN.

gassma.sheet1.updateMany({ data: { age: 1 }, limit: null });
// => Invalid value for argument `limit`. Expected a number, but received null.

The finiteness check runs first, so limit: -Infinity throws GassmaInvalidValueError rather than GassmaLimitNegativeError. undefined is ignored (no upper bound).

Atomic Number Operations​

By specifying increment / decrement / multiply / divide in data, you can perform operations on the current value:

// Increment everyone's age by 1
const result = gassma.sheet1.updateMany({
data: {
age: { increment: 1 },
},
});
OperationBehaviorExample
incrementAddition{ increment: 5 } → current value + 5
decrementSubtraction{ decrement: 3 } → current value - 3
multiplyMultiplication{ multiply: 2 } → current value × 2
divideDivision{ divide: 4 } → current value ÷ 4

If the current value is not a number, 0 is used as the base for calculations. For details, see update().