Hierarchy

  • DB

Constructors

  • Example

    import { DB } from "node-firestore";

    const db = new DB("./firebase-key.json")

    // OR

    const db2 = new DB({
    clientEmail: "myClient@email.com",
    privateKey: "----BEGIN PRIVATE KEY-----.......-----END PRIVATE KEY-----",
    projectId: "myProjectId"
    })

    Parameters

    • config: ConfigLike

      Path to the firebase service account or the config in json itself

    Returns DB

Properties

app: App
config: string | ServiceAccount
db: Firestore

Methods

  • Async

    This function is async, so please use await/promise syntax accordingly.

    Description

    create a new document in the specified collection with the specified name if it doesn't already exist, then stores the data in the document

    Remarks

    Modifies the data if the document already exists.

    Example

    import { DB } from "node-firestore";

    const db = new DB(config);
    const successful = db.addData("foo", "bar", { hello: "world" });

    if (!successful) {
    console.error("There was an error adding data to the DB!")
    }

    Parameters

    • collectionName: StringLike

      name of the collection to add data to.

    • documentName: StringLike

      name of the document to add data to.

    • data: DataLike

      The data to add to the document.

    Returns Promise<boolean>

    true if successful or false if unsuccessful.

  • Parameters

    • query: Query<DocumentData>

    Returns Promise<boolean>

  • Async

    This function is async, so please use await/promise syntax accordingly.

    Description

    deletes the specified collection

    Example

    import { DB } from "node-firestore";

    const db = new DB(config);
    const deleteCollectionSuccess = db.deleteCollection("foo");

    if (!deleteCollectionSuccess) {
    console.error("There was an error deleting a collection!")
    }

    Parameters

    • collectionName: StringLike

      The name of the collection to delete

    • batchSize: NumberLike = 5

      The size of the batches to delete

    Returns Promise<Boolean>

    true is successful or false if unsuccessful

  • Async

    This function is async, so please use await/promise syntax accordingly.

    Description

    deleted the specified document in the specified collection

    Example

    import { DB } from "node-firestore";

    const db = new DB(config);

    const deleteSuccess = db.deleteDocument("foo",
    bar)

    if (!deleteSuccess) {
    console.error("There was an error deleting a document!");
    }

    Parameters

    • collectionName: StringLike

      The name of the collection

    • documentName: StringLike

      The name of the document

    Returns Promise<Boolean>

    true if successful, or false if unsuccessful

  • Async

    This function is async, so please use await/promise syntax accordingly.

    Description

    gets data from the specified document in th specified collection.

    Example

    import { DB } from "node-firestore";

    const db = new DB(config);

    const data = db.getData("foo", "bar");

    if (!data) {
    console.error("There was an error retrieving data from the DB!")
    }

    Parameters

    • collectionName: StringLike

      name of the collection to add data to.

    • documentName: StringLike

      name of the document to add data to.

    Returns Promise<false | DocumentData>

    data if successful or false if unsuccessful

Generated using TypeDoc