Edits history of script submission #22366 for ' Create Document (firebase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { initializeApp } from "[email protected]/app";
    import { addDoc, collection, getFirestore } from "[email protected]/firestore/lite";
    
    /**
     * Learn more about adding documents at
     * https://firebase.google.com/docs/firestore/manage-data/add-data
     *
     * @returns The ID of the new document.
     */
    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: Record<string, any>,
    ) {
      const app = initializeApp(auth);
      const store = getFirestore(app);
    
      const colRef = collection(store, collection_id);
      const res = await addDoc(colRef, document);
    
      return res.id;
    }
    

    Submitted by hugo989 7 days ago