Skip to content

Model.updateMany ​

Call User.updateMany(filter, changes) on an imported model. The filter must be a non-empty object, and changes must contain at least one known model field. The @id field cannot be changed.

The update is parameterized and applies to every record matching the filter. It returns Promise<Result<u64, DbError>>; the success value is the number of updated records. Database constraint and connection failures are recoverable DbError values.

This fragment assumes an imported User model with id marked @id and email and displayName fields.

tyrus
import { DbError } from "tyrus:db";
import { User } from "./models/User";

async function updateExampleUsers(): Promise<Result<u64, DbError>> {
    const data = await User.updateMany(
        { email: { like: "%@example.com" } },
        { displayName: "Member" }
    ) onfail {
        return Err(data);
    };
    return Ok(data);
}

Use Model.updateOne(filter, changes) when the filter identifies one @id or @unique field.