• Updates the specified document in the provided Firestore collection with the given data.

    Throws

    Throws an exception with an error message if an error occurs.

    Example

    import { firestore } from 'firebase-admin'
    import { update } from '@skeet-framework/firestore'

    const db = firestore();
    const updatedData: firestore.UpdateData<User> = {
    age: 31
    };

    async function run() {
    try {
    const path = 'Users'
    const docId = '123456'; // Assuming this ID exists in the Users collection.
    const success = await update<User>(db, path, docId, updatedData);
    if (success) {
    console.log(`Document with ID ${docId} updated successfully.`);
    }
    } catch (error) {
    console.error(`Error updating document: ${error}`);
    }
    }

    run();

    Type Parameters

    • T extends DocumentData

    Parameters

    • db: Firestore

      The instance of the Firestore database to use.

    • collectionPath: string

      The path of the collection containing the document to be updated.

    • docId: string

      The ID of the document to be updated.

    • params: UpdateData<T>

      The data to update the document with.

    Returns Promise<boolean>

    A boolean indicating the success of the update operation.

Generated using TypeDoc