Skip to content
This repository was archived by the owner on Sep 28, 2026. It is now read-only.
This repository was archived by the owner on Sep 28, 2026. It is now read-only.

How can I choose a custom database ID instead of the (default) one?  #130

Open

Description

@mailaneel

Reopening #126

databaseId is second param to getFirestore, without this it always uses (default) database

return getFirestore(app);

Activity

  1. kossnocorp commented on Apr 19, 2024

    @kossnocorp
    Owner

    Hey! You can configure it using the options schema argument: https://typesaurus.com/api/schema/#app

  2. mailaneel commented on Apr 20, 2024

    @mailaneel
    Author

    @kossnocorp apologies for raising this again, I tried using the schema option like you have suggested, but it didn't work as expected.

    Below is the logic used in typesaurus to get firestore, when we pass { app: 'some-name' } assuming some-name is the name of the firestore database. we are getting app instance with different name, but firestore is still using default database (getFirestore logic added below). Also I don't see a option to pass to initializeApp

    export function firestore(options) {
      const appName = options?.server?.app || options?.app;
      const app = getApp(appName);
    
      if (options?.server?.preferRest) {
        return initializeFirestore(app, {
          preferRest: options?.server?.preferRest,
        });
      } else {
        return getFirestore(app);
      }
    }

    getFirestore from firebase.js

    export function getFirestore(app: App, databaseId: string): Firestore;
    
    export function getFirestore(
      appOrDatabaseId?: App | string,
      optionalDatabaseId?: string
    ): Firestore {
      const app: App = typeof appOrDatabaseId === 'object' ? appOrDatabaseId : getApp();
      const databaseId =
        (typeof appOrDatabaseId === 'string' ? appOrDatabaseId : optionalDatabaseId) || DEFAULT_DATABASE_ID;
      const firebaseApp: FirebaseApp = app as FirebaseApp;
      const firestoreService = firebaseApp.getOrInitService(
        'firestore', (app) => new FirestoreService(app));
      return firestoreService.getDatabase(databaseId);
    }
  3. kossnocorp commented on May 13, 2024

    @kossnocorp
    Owner

    Hey, sorry that it doesn't work for you. Let me reopen the issue, add tests and fix it.

  4. ecaroth commented on Aug 22, 2024

    @ecaroth

    I had this need myself, just submitted a PR that fixes it @kossnocorp
    #139

  5. aaaaahaaaaa commented on Sep 9, 2024

    @aaaaahaaaaa

    @kossnocorp Can we get a bit of love on this issue and get this merged and released? Not being able to select a different DB is a hard blocker for many I'm sure. This feature has been GA in Firestore since February.

  6. LeoTheG commented on Sep 8, 2025

    @LeoTheG

    @kossnocorp are there any updates on this? It's critical to my work that we're able to specify DBs

  7. ochoalopezalfredo commented on Nov 28, 2025

    @ochoalopezalfredo

    @LeoTheG , @aaaaahaaaaa, @mailaneel

    @kossnocorp I create the PR #147 that solve this issue

    Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions