I need to connect a second Firestore db to my Angular app and havent found a clean way to accomplish this. I have seen this challenge solved on stack in the past (How can I connect two databases with @angular/fire?) & have read this great article (https://medium.com/@handersonc/connecting-angular-with-multiple-firebase-projects-889bb7de1f56) however with the newest flavor of AngularFire (7.5) changing both the injected functions and the syntax, I'm not quite sure how to accomplish this.
Below is a summarized version of my setup. Would someone help or a least point me in the right direction? Thanks so much.
app.module.ts
import { environment } from '../environments/environment';
import { initializeApp,provideFirebaseApp } from '@angular/fire/app';
import { provideAuth,getAuth } from '@angular/fire/auth';
import { provideFirestore,getFirestore } from '@angular/fire/firestore';
@NgModule({
declarations: [
AppComponent,
HomeLayout
],
imports: [
BrowserModule,
AppRoutingModule,
provideFirebaseApp(() => initializeApp(environment.firebase-proj-1)),
provideAuth(() => getAuth()),
provideFirestore(() => getFirestore()),
],
providers: [
ScreenTrackingService,UserTrackingService
],
bootstrap: [AppComponent]
})
environment.prod.ts
export const environment = {
production: true,
firebase-proj-1: {
projectId: 'xxx',
appId: 'xxx',
storageBucket: 'xxx',
apiKey: 'xxx',
authDomain: 'xxx',
messagingSenderId: 'xxx',
measurementId: 'xxx',
},
firebase-proj-2: {
apiKey: "xxx",
authDomain: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
measurementId: "xxx"
}
};
publications.service.ts
import { Injectable } from '@angular/core';
import { Firestore, collectionData, collection,
addDoc, QueryConstraint, query } from '@angular/fire/firestore';
import { orderBy } from 'firebase/firestore';
@Injectable({
providedIn: 'root'
})
export class PubService {
collectionPath = collection(this.firestore, 'publications')
constructor( private firestore: Firestore ) { }
getPubs(){
const contraints:QueryConstraint[] = [orderBy('name', 'asc')]
return collectionData(query(this.collectionPath, ...contraints), {idField: 'id'})
}
createPub(form: unknown){
return addDoc(this.collectionPath, form)
}
}