Interface MongodbModel<IdType>

Shape of the model static properties.

interface MongodbModel {
    new MongodbModelnew (): MongodbDocument<IdType>;
    $fieldsDefinitions: Map<string, FieldOptions>;
    booted: boolean;
    collectionName?: string;
    connection?: string;
    $addComputed(name, options): ComputedOptions;
    $addField(name, options?): FieldOptions;
    $getComputed(name): undefined | ComputedOptions;
    $getField(name): undefined | FieldOptions;
    $hasComputed(name): boolean;
    $hasField(name): boolean;
    all<ModelType>(this, options?): Promise<InstanceType<ModelType>[]>;
    boot(): void;
    count<ModelType>(this, filter, options?): Promise<number>;
    create<ModelType>(this, value, options?): Promise<InstanceType<ModelType>>;
    createMany<ModelType>(this, values, options?): Promise<InstanceType<ModelType>[]>;
    find<ModelType>(this, id, options?): Promise<null | InstanceType<ModelType>>;
    findBy<ModelType>(this, key, value, options?): Promise<null | InstanceType<ModelType>>;
    findByOrFail<ModelType>(this, key, value, options?): Promise<InstanceType<ModelType>>;
    findMany<ModelType>(this, ids, options?): Promise<InstanceType<ModelType>[]>;
    findOrFail<ModelType>(this, id, options?): Promise<InstanceType<ModelType>>;
    getCollection<ModelType>(this, connection?): Promise<Collection<ModelAttributes<InstanceType<ModelType>>>>;
    query<ModelType>(this, filter?, options?): 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

  • Count the number of documents in the collection that match the filter.

    Type Parameters

    Parameters

    Returns Promise<number>

  • Create a new document in the collection.

    Type Parameters

    Parameters

    Returns Promise<InstanceType<ModelType>>

  • Create many documents in the collection.

    Type Parameters

    Parameters

    Returns Promise<InstanceType<ModelType>[]>

  • Find a document by its id.

    Type Parameters

    Parameters

    Returns Promise<null | InstanceType<ModelType>>

  • Find a document using a key-value pair.

    Type Parameters

    Parameters

    Returns Promise<null | InstanceType<ModelType>>

  • Find a document using a key-value pair. Throw if no document is found.

    Type Parameters

    Parameters

    Returns Promise<InstanceType<ModelType>>

  • Find many documents by their ids.

    Type Parameters

    Parameters

    Returns Promise<InstanceType<ModelType>[]>

  • Find a document by its id. Throw if no document is found.

    Type Parameters

    Parameters

    Returns Promise<InstanceType<ModelType>>

  • Get the collection object from the MongoDB driver.

    Type Parameters

    Parameters

    • this: ModelType
    • Optional connection: string

    Returns Promise<Collection<ModelAttributes<InstanceType<ModelType>>>>