Edits history of script submission #359 for ' Set Document (firebase)'

  • deno
    import { initializeApp } from "npm:[email protected]/app";
    import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
    
    /**
     * Overwrites or updates a document.
     *
     * @param document_path Path to the document.
     * If you want to update a top-level document by ID, pass in an array with only
     * the ID in it.
     * *eg:* `[ 'my-id' ]`
     *
     * @param merge If `true`, the document will be updated with provided fields,
     * otherwise the document will be completely overwritten.
     * **WARNING:** Overwriting a document may result in data loss.
     *
     * @param mergeFields Controls which fields should be merged.
     */
    type Firebase = {
      apiKey: string;
      authDomain: string;
      projectId: string;
      storageBucket: string;
      messagingSenderId: string;
      appId: string;
      measurementId: string;
    };
    export async function main(
      auth: Firebase,
      collection_id: string,
      document_path: string[],
      document: Record<string, any>,
      merge?: boolean,
      mergeFields?: string[],
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const docRef = doc(store, collection_id, ...document_path);
      await setDoc(docRef, document, {
        merge: typeof merge === "boolean" ? merge : undefined,
        mergeFields:
          Array.isArray(mergeFields) && mergeFields.length
            ? mergeFields
            : undefined,
      });
    }
    

    Submitted by hugo697 399 days ago

  • deno
    import { initializeApp } from "npm:[email protected]/app";
    import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
    
    /**
     * Overwrites or updates a document.
     *
     * @param document_path Path to the document.
     * If you want to update a top-level document by ID, pass in an array with only
     * the ID in it.
     * *eg:* `[ 'my-id' ]`
     *
     * @param merge If `true`, the document will be updated with provided fields,
     * otherwise the document will be completely overwritten.
     * **WARNING:** Overwriting a document may result in data loss.
     *
     * @param mergeFields Controls which fields should be merged.
     */
    type Firebase = {
      apiKey: string;
      authDomain: string;
      projectId: string;
      storageBucket: string;
      messagingSenderId: string;
      appId: string;
      measurementId: string;
    };
    export async function main(
      auth: Firebase,
      collection_id: string,
      document_path: string[],
      document: Record<string, any>,
      merge?: boolean,
      mergeFields?: string[],
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const docRef = doc(store, collection_id, ...document_path);
      await setDoc(docRef, document, {
        merge: typeof merge === "boolean" ? merge : undefined,
        mergeFields:
          Array.isArray(mergeFields) && mergeFields.length
            ? mergeFields
            : undefined,
      });
    }
    

    Submitted by admin 1031 days ago

  • deno
    import { initializeApp } from "npm:[email protected]/app";
    import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
    
    /**
     * Overwrites or updates a document.
     *
     * @param document_path Path to the document.
     * If you want to update a top-level document by ID, pass in an array with only
     * the ID in it.
     * *eg:* `[ 'my-id' ]`
     *
     * @param merge If `true`, the document will be updated with provided fields,
     * otherwise the document will be completely overwritten.
     * **WARNING:** Overwriting a document may result in data loss.
     *
     * @param mergeFields Controls which fields should be merged.
     */
    type Firebase = {
      apiKey: string;
      authDomain: string;
      projectId: string;
      storageBucket: string;
      messagingSenderId: string;
      appId: string;
      measurementId: string;
    };
    export async function main(
      auth: Firebase,
      collection_id: string,
      document_path: string[],
      document: Record<string, any>,
      merge?: boolean,
      mergeFields?: string[],
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const docRef = doc(store, collection_id, ...document_path);
      await setDoc(docRef, document, {
        merge: typeof merge === "boolean" ? merge : undefined,
        mergeFields: Array.isArray(mergeFields) && mergeFields.length
          ? mergeFields
          : undefined,
      });
    }
    

    Submitted by admin 1034 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { initializeApp } from "npm:[email protected]/app";
    import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
    
    /**
     * Overwrites or updates a document.
     *
     * @param document_path Path to the document.
     * If you want to update a top-level document by ID, pass in an array with only
     * the ID in it.
     * *eg:* `[ 'my-id' ]`
     *
     * @param merge If `true`, the document will be updated with provided fields,
     * otherwise the document will be completely overwritten.
     * **WARNING:** Overwriting a document may result in data loss.
     *
     * @param mergeFields Controls which fields should be merged.
     */
    export async function main(
      auth: Resource<"firebase">,
      collection_id: string,
      document_path: string[],
      document: Record<string, any>,
      merge?: boolean,
      mergeFields?: string[],
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const docRef = doc(store, collection_id, ...document_path);
      await setDoc(docRef, document, {
        merge: typeof merge === "boolean" ? merge : undefined,
        mergeFields: Array.isArray(mergeFields) && mergeFields.length
          ? mergeFields
          : undefined,
      });
    }
    

    Submitted by adam186 1140 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { initializeApp } from "npm:[email protected]/app";
    import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
    
    /**
     * Overwrites or updates a document.
     *
     * @param document_path Path to the document.
     * If you want to update a top-level document by ID, pass in an array with only
     * the ID in it.
     * *eg:* `[ 'my-id' ]`
     *
     * @param merge If `true`, the document will be updated with provided fields,
     * otherwise the document will be completely overwritten.
     * **WARNING:** Overwriting a document may result in data loss.
     *
     * @param mergeFields Controls which fields should be merged.
     *
     * @returns The ID of the document that was attempted to update.
     */
    export async function main(
      auth: Resource<"firebase">,
      collection_id: string,
      document_path: string[],
      document: Record<string, any>,
      merge?: boolean,
      mergeFields?: string[],
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const docRef = doc(store, collection_id, ...document_path);
      await setDoc(docRef, document, {
        merge: typeof merge === "boolean" ? merge : undefined,
        mergeFields: Array.isArray(mergeFields) && mergeFields.length
          ? mergeFields
          : undefined,
      });
    }
    

    Submitted by adam186 1140 days ago