How to access non-default Firestore database in AngularFire

Discussão em 'Angular' iniciado por chumberjosh, Janeiro 15, 2025.

  1. chumberjosh

    chumberjosh Guest

    I'm trying to access another firestore database in my gcloud project. I can access the default one (default) fine, but I have one called 'development' that I can't access, and can't find any documentation online of how to access it.

    When I got my initial firebase config it did not include a databaseURL, but i've added one to try and access the database but it doesn't work. This is how my config currently looks

    export const firebaseConfig = {
    apiKey: <apiKey>,
    authDomain: <authDomain>,
    projectId: <projectId>,
    storageBucket: <storageBucket>,
    messagingSenderId: <messagingSenderId>,
    appId: <appId>,
    databaseURL: "https://firestore.googleapis.com/v1/projects/<projectId>/databases/development/",
    measurementId: <measurementId>,
    databaseId: "development",
    };

    export const environment = {
    production: false,
    firebaseConfig: firebaseConfig,
    databaseName: 'development',
    };

    // From looking at the docs, the default databaseURL would be "https://firestore.googleapis.com/v1/projects/<projectId>/databases/(default)/"


    I am importing in my app.module like this

    AngularFireModule.initializeApp(environment.firebaseConfig,),
    AngularFirestoreModule


    I've also tried

    AngularFireModule.initializeApp(environment.firebaseConfig, {name: environment.databaseName}),


    and

    AngularFireModule.initializeApp(environment.firebaseConfig, environment.databaseName),


    If I go to the databaseURL in a web browser, it comes up with


    Missing routing header. Please fill in the request header with format x-goog-request-params:project_id=pocketmechanic-2970f&database_id=development. Please refer to https://firebase.google.com/docs/fi...access_a_named_database_with_a_client_library for more details.
    ​

    Continue reading...

Compartilhe esta Página