firewalk
    Preparing search index...

    Interface BatchMigrator<AppModelType, DbModelType>

    A batch migrator object that uses atomic batch writes.

    interface BatchMigrator<
        AppModelType = firestore.DocumentData,
        DbModelType extends firestore.DocumentData = firestore.DocumentData,
    > {
        traverser: Traverser<AppModelType, DbModelType>;
        deleteField(field: string | FieldPath): Promise<MigrationResult>;
        deleteFields(...fields: (string | FieldPath)[]): Promise<MigrationResult>;
        onAfterBatchComplete(
            callback: BatchCallback<AppModelType, DbModelType>,
        ): void;
        onBeforeBatchStart(
            callback: BatchCallback<AppModelType, DbModelType>,
        ): void;
        renameField(
            oldField: string | FieldPath,
            newField: string | FieldPath,
        ): Promise<MigrationResult>;
        renameFields(
            ...changes: [
                oldField: string
                | FieldPath,
                newField: string | FieldPath,
            ][],
        ): Promise<MigrationResult>;
        set(
            data: PartialWithFieldValue<AppModelType>,
            options: SetOptions,
        ): Promise<MigrationResult>;
        set(data: WithFieldValue<AppModelType>): Promise<MigrationResult>;
        setWithDerivedData(
            getData: SetPartialDataGetter<AppModelType, DbModelType>,
            options: SetOptions,
        ): Promise<MigrationResult>;
        setWithDerivedData(
            getData: SetDataGetter<AppModelType, DbModelType>,
        ): Promise<MigrationResult>;
        update(
            data: UpdateData<DbModelType>,
            precondition?: Precondition,
        ): Promise<MigrationResult>;
        update(
            field: string | FieldPath,
            value: any,
            ...moreFieldsOrPrecondition: any[],
        ): Promise<MigrationResult>;
        updateWithDerivedData(
            getData: UpdateDataGetter<AppModelType, DbModelType>,
            precondition?: Precondition,
        ): Promise<MigrationResult>;
        updateWithDerivedData(
            getData: UpdateFieldValueGetter<AppModelType, DbModelType>,
        ): Promise<MigrationResult>;
        withPredicate(
            predicate: MigrationPredicate<AppModelType, DbModelType>,
        ): BatchMigrator<AppModelType, DbModelType>;
        withTraverser(
            traverser: Traverser<AppModelType, DbModelType>,
        ): BatchMigrator<AppModelType, DbModelType>;
    }

    Type Parameters

    • AppModelType = firestore.DocumentData
    • DbModelType extends firestore.DocumentData = firestore.DocumentData

    Hierarchy (View Summary)

    Index

    Properties

    The underlying traverser.

    Methods

    • Deletes the specified field from all documents in this collection.

      Parameters

      • field: string | FieldPath

        The field to delete.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Deletes the specified fields from all documents in this collection.

      Parameters

      • ...fields: (string | FieldPath)[]

        A list of fields to delete.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
      const field1 = new firestore.FieldPath('name', 'last');
      const field2 = 'lastModifiedAt';
      await migrator.deleteFields(field1, field2);
    • Renames the specified field in all documents in this collection. Ignores the fields that are missing.

      Parameters

      • oldField: string | FieldPath

        The old field.

      • newField: string | FieldPath

        The new field.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Renames the specified fields in all documents in this collection. Ignores the fields that are missing.

      Parameters

      • ...changes: [oldField: string | FieldPath, newField: string | FieldPath][]

        A list of [oldField, newField] tuples. Each tuple is an array of 2 elements: the old field to rename and the new field.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
      const change1 = [new firestore.FieldPath('name', 'last'), 'lastName'];
      const change2 = ['lastModifiedAt', 'lastUpdatedAt'];
      await migrator.renameFields(change1, change2);
    • Sets all documents in this collection with the provided data.

      Parameters

      • data: PartialWithFieldValue<AppModelType>

        A data object with which to set each document.

      • options: SetOptions

        An object to configure the set behavior.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Sets all documents in this collection with the provided data.

      Parameters

      • data: WithFieldValue<AppModelType>

        A data object with which to set each document.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Sets all documents in this collection with the provided data.

      Parameters

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Sets all documents in this collection with the provided data.

      Parameters

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Updates all documents in this collection with the provided data.

      Parameters

      • data: UpdateData<DbModelType>

        A non-empty data object with which to update each document.

      • Optionalprecondition: Precondition

        A Precondition to enforce on this update.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Updates all documents in this collection with the provided field-value pair.

      Parameters

      • field: string | FieldPath

        The first field to update in each document.

      • value: any

        The first value corresponding to the first field. Must not be undefined.

      • ...moreFieldsOrPrecondition: any[]

        An alternating list of field paths and values to update, optionally followed by a Precondition to enforce on this update.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Updates all documents in this collection with the provided data.

      Parameters

      • getData: UpdateDataGetter<AppModelType, DbModelType>

        A function that takes a document snapshot and returns a non-empty data object with which to update each document.

      • Optionalprecondition: Precondition

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Updates all documents in this collection with the provided data.

      Parameters

      • getData: UpdateFieldValueGetter<AppModelType, DbModelType>

        A function that takes a document snapshot and returns an alternating list of field paths and values to update, optionally followed by a Precondition to enforce on this update.

      Returns Promise<MigrationResult>

      A Promise resolving to an object representing the details of the migration.

      Complexity:

      • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
      • Space complexity: SC(traverser) where S = O(batchSize)
      • Billing: max(1, N) reads, K writes

      where:

      • N: number of docs in the traversable
      • K: number of docs that passed the migration predicate (K<=N)
      • W(batchSize): average batch write time
      • TC(traverser): time complexity of the underlying traverser
      • SC(traverser): space complexity of the underlying traverser
    • Applies a migration predicate that indicates whether to migrate the current document or not. By default, all documents are migrated.

      Parameters

      Returns BatchMigrator<AppModelType, DbModelType>

      A new BatchMigrator object.

      If you have already applied other migration predicates to this migrator, this and all the other predicates will be evaluated and the resulting booleans will be AND'd to get the boolean that indicates whether to migrate the document or not. This is consistent with the intuitive default behavior that all documents are migrated.

      const newMigrator = migrator
      .withPredicate((doc) => doc.get('name') !== undefined)
      .withPredicate((doc) => doc.ref.path.startsWith('users/'));

      In the above case newMigrator will migrate only the documents whose name field is not missing AND whose path starts with "users/".