question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find how to pass firestore settings using a new modular API

See original GitHub issue

Version info

Angular: 12.1.1

Firebase: 9.1.3

AngularFire: 7.1.0

With old API, we could pass settings (for example ignoreUndefinedProperties: true) into firestore using provider FIRESTORE_SETTINGS as folowing:

import {SETTINGS as FIRESTORE_SETTINGS} from '@angular/fire/compat/firestore';

@NgModule({
      imports: [
        AngularFireModule.initializeApp(environment.firebaseConfig, 'My-App'),
      ],
      providers: [
        // ...
        {
          provide: FIRESTORE_SETTINGS,
          useValue: { ignoreUndefinedProperties: true }
        },
      ]
})

After consulting documentation and source code of angularfire I coundn’t find the way to do the same with new modular API:

@NgModule({
  imports: [
    // ...
    provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
    provideFirestore(() => {
      const firestore = getFirestore();
      if (!environment.production) {
        connectFirestoreEmulator(firestore, 'localhost', 8080);
      }
      return firestore;
    }),
  ]
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
hosuabycommented, Apr 24, 2022

@skog-newglue looks like you are mixing new and old API. Start by removing everything imported from @angular/fire/compat/* :

import { environment } from '../environments/environment';
import { APP_BASE_HREF } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { initializeFirestore, provideFirestore } from '@angular/fire/firestore';
import { initializeAppCheck, provideAppCheck, ReCaptchaV3Provider } from '@angular/fire/app-check';
import { getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideFirestore(() => initializeFirestore(getApp(), { ignoreUndefinedProperties: true })), // Not working
    provideAppCheck(() =>
      initializeAppCheck(getApp(), { provider: new ReCaptchaV3Provider(environment.recaptchaSiteKey), isTokenAutoRefreshEnabled: true })
    ),
  ],
  providers: [
    { provide: APP_BASE_HREF, useValue: '/' },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

And in your client code use:

constructor(private readonly firestore: Firestore) {
  // ...
}
1reaction
hosuabycommented, Apr 13, 2022

@anisabboud this code works. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started with Cloud Firestore - Firebase
This quickstart shows you how to set up Cloud Firestore, add data, then view the data you just added in the Firebase console....
Read more >
How to upgrade to Node.js SDK Admin SDK v10 (modular ...
from 'firebase-admin/messaging' const messaging = getMessaging(); const firestore = getFirestore(); import DocumentSnapshot = functions.  ...
Read more >
Adding data | Firestore - Google Cloud
There are several ways to write data to Firestore: Set the data of a document within a collection, explicitly specifying a document identifier....
Read more >
Firebase / Firestore Integration - Retool Docs
The query the RealtimeDB, create a new query (+new in the bottom panel), and select your Firebase resource from the resource dropdown. Then,...
Read more >
Firebase Modular JavaScript SDK Documentation
import firebase from 'firebase/app'; import 'firebase/auth'; firebase.initializeApp({ /* config */ }); const auth = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found