diff --git a/src/firebase.ts b/src/firebase.ts index 4f375ed..10ec981 100644 --- a/src/firebase.ts +++ b/src/firebase.ts @@ -1,5 +1,8 @@ import { initializeApp, cert } from 'firebase-admin/app'; -import { getFirestore } from 'firebase-admin/firestore'; +import { + getFirestore, + initializeFirestore, +} from 'firebase-admin/firestore'; // The service account key determines which Firebase project we're using. @@ -12,10 +15,7 @@ const app = initializeApp( 'ltijs-firestore', // Provide a named instance so multiple apps can be initialized: https://github.com/examind-ai/ltijs-firestore/issues/3 ); -const db = getFirestore(app); - -db.settings({ - ignoreUndefinedProperties: true, +const db = initializeFirestore(app, { // Faster cold starts by using REST (instead of gRPC) where possible: https://github.com/firebase/firebase-admin-node/pull/1901 // As of 2023-07-06, the only operation that requires gRPC is onSnapshot(), which we don't use on the server: https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings // Cold start issue tracker: https://issuetracker.google.com/issues/158014637#comment212 @@ -23,4 +23,8 @@ db.settings({ preferRest: !process.env.FIRESTORE_EMULATOR_HOST, }); +db.settings({ + ignoreUndefinedProperties: true, +}); + export { db };