@zakodium/adonis-mongodb
    Preparing search index...

    Interface MongodbDocument<IdType>

    interface MongodbDocument<IdType> {
        _id: IdType;
        $attributes: ModelAttributes<this>;
        $dirty: Partial<ModelAttributes<this>>;
        $isDeleted: boolean;
        $isDirty: boolean;
        $isLocal: boolean;
        $isNew: boolean;
        $isPersisted: boolean;
        $isTransaction: boolean;
        $original: ModelAttributes<this>;
        $trx: undefined | ClientSession;
        createdAt: Date;
        id: IdType;
        updatedAt: Date;
        delete(options?: ModelDocumentOptions<DeleteOptions>): Promise<boolean>;
        fill<
            T extends
                Partial<Omit<ModelAttributes<MongodbDocument<IdType>>, "_id">>,
        >(
            values: NoExtraProperties<
                Partial<Omit<ModelAttributes<MongodbDocument<IdType>>, "_id">>,
                T,
            >,
        ): this;
        merge<
            T extends
                Partial<Omit<ModelAttributes<MongodbDocument<IdType>>, "_id">>,
        >(
            values: NoExtraProperties<
                Partial<Omit<ModelAttributes<MongodbDocument<IdType>>, "_id">>,
                T,
            >,
        ): this;
        save(options?: ModelDocumentOptions<InsertOneOptions>): Promise<boolean>;
        toJSON(): unknown;
        useTransaction(client: ClientSession): this;
    }

    Type Parameters

    • IdType
    Index

    Properties

    _id: IdType
    $attributes: ModelAttributes<this>
    $dirty: Partial<ModelAttributes<this>>

    Returns an object with the field values that have been changed.

    $isDeleted: boolean

    true if the entry has been removed from the database.

    $isDirty: boolean

    true if the entry has unsaved modifications.

    $isLocal: boolean

    true if the entry has been created locally. Similar to $isNew, but stays true after the entry is persisted to the database.

    $isNew: boolean

    Opposite of $isPersisted.

    $isPersisted: boolean

    true if the entry has been persisted to the database.

    $isTransaction: boolean
    $original: ModelAttributes<this>
    $trx: undefined | ClientSession

    Return the client session of the transaction

    createdAt: Date
    id: IdType
    updatedAt: Date

    Methods

    • Assign client to model options for transactions use. Will throw an error if model instance already linked to a session

      It allows to use model init outside a transaction, but save it within a transaction.

      Parameters

      • client: ClientSession

      Returns this

      const label = await Label.findOrFail(1);
      // edit some label props

      Database.transaction((client) => {
      const documents = await Document.query({ labels: label._id }, { client }).all()
      // remove label from documents when new label definition is incompatible
      // call .save() for each changed documents (aware of transaction because is from query with client option)

      label.useTransaction(client);
      label.save();
      })