Interface MongodbModel<IdType>

Shape of the model static properties.

interface MongodbModel<IdType> {
    new MongodbModel(): MongodbDocument<IdType>;
    $fieldsDefinitions: Map<string, FieldOptions>;
    booted: boolean;
    collectionName?: string;
    connection?: string;
    $addComputed(
        name: string,
        options: Partial<ComputedOptions>,
    ): ComputedOptions;
    $addField(name: string, options?: Partial<FieldOptions>): FieldOptions;
    $getComputed(name: string): undefined | ComputedOptions;
    $getField(name: string): undefined | FieldOptions;
    $hasComputed(name: string): boolean;
    $hasField(name: string): boolean;
    all<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<InstanceType<ModelType>[]>;
    boot(): void;
    count<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        filter: Filter<ModelAttributes<InstanceType<ModelType>>>,
        options?: ModelAdapterOptions<CountDocumentsOptions>,
    ): Promise<number>;
    create<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        value: Partial<ModelAttributes<InstanceType<ModelType>>>,
        options?: ModelAdapterOptions<InsertOneOptions>,
    ): Promise<InstanceType<ModelType>>;
    createMany<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        values: Partial<ModelAttributes<InstanceType<ModelType>>>[],
        options?: ModelAdapterOptions<BulkWriteOptions>,
    ): Promise<InstanceType<ModelType>[]>;
    find<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        id: InstanceType<ModelType>["_id"],
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<null | InstanceType<ModelType>>;
    findBy<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        key: string,
        value: unknown,
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<null | InstanceType<ModelType>>;
    findByOrFail<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        key: string,
        value: unknown,
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<InstanceType<ModelType>>;
    findMany<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        ids: InstanceType<ModelType>["_id"][],
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<InstanceType<ModelType>[]>;
    findOrFail<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        id: InstanceType<ModelType>["_id"],
        options?: ModelAdapterOptions<
            FindOptions<ModelAttributes<InstanceType<ModelType>>>,
        >,
    ): Promise<InstanceType<ModelType>>;
    getCollection<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        connection?: string,
    ): Promise<Collection<ModelAttributes<InstanceType<ModelType>>>>;
    query<ModelType extends MongodbModel<IdType>>(
        this: ModelType,
        filter?: Filter<ModelAttributes<InstanceType<ModelType>>>,
        options?: ModelAdapterOptions<
            Omit<
                FindOptions<ModelAttributes<InstanceType<ModelType>>>,
                ForbiddenQueryOptions,
            >,
        >,
    ): QueryContract<InstanceType<ModelType>>;
}

Type Parameters

  • IdType

Constructors

Properties

$fieldsDefinitions: Map<string, FieldOptions>

Map of the fields that exist on the model.

booted: boolean

Whether the model has been booted.

collectionName?: string

Name of the collection to use.

connection?: string

Custom database connection to use.

Methods

  • Returns whether the field exists on the model.

    Parameters

    • name: string

    Returns boolean