Skip to content

Model.deleteMany ​

Call User.deleteMany(filter) on an imported model. The filter must be a non-empty object. Every filter value is parameterized, and the compiler checks field names and value types against the model and schema snapshot.

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

This fragment assumes an imported User model with an email field.

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

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

Use Model.deleteOne(filter) when the filter identifies one @id or @unique field.