0

Delete Document

by
Published Apr 27, 2023
Script firebase Verified

The script

Submitted by hugo989 Bun
Verified 6 days ago
1
import { initializeApp } from "[email protected]/app";
2
import { deleteDoc, doc, getFirestore } from "[email protected]/firestore/lite";
3

4
/**
5
 * Deletes a document.
6
 */
7
type Firebase = {
8
  apiKey: string;
9
  authDomain: string;
10
  projectId: string;
11
  storageBucket: string;
12
  messagingSenderId: string;
13
  appId: string;
14
  measurementId: string;
15
};
16
export async function main(
17
  auth: Firebase,
18
  collection_id: string,
19
  document_path: string[],
20
) {
21
  const app = initializeApp(auth);
22
  const store = getFirestore(app);
23

24
  const docRef = doc(store, collection_id, ...document_path);
25
  await deleteDoc(docRef);
26
}
27

Other submissions
  • Submitted by adam186 Deno
    Created 398 days ago
    1
    import { initializeApp } from "npm:[email protected]/app";
    2
    import { deleteDoc, doc, getFirestore } from "npm:firebase/firestore/lite";
    3
    
    
    4
    /**
    5
     * Deletes a document.
    6
     */
    7
    type Firebase = {
    8
      apiKey: string;
    9
      authDomain: string;
    10
      projectId: string;
    11
      storageBucket: string;
    12
      messagingSenderId: string;
    13
      appId: string;
    14
      measurementId: string;
    15
    };
    16
    export async function main(
    17
      auth: Firebase,
    18
      collection_id: string,
    19
      document_path: string[],
    20
    ) {
    21
      const app = initializeApp(auth);
    22
      const store = getFirestore(app);
    23
    
    
    24
      const docRef = doc(store, collection_id, ...document_path);
    25
      await deleteDoc(docRef);
    26
    }
    27