Using firebase-admin (>10.0.x)
which is now modular, we initialize an app like this in Node.JS:
import { initializeApp } from 'firebase-admin/app'
import { getFirestore } from "firebase-admin/firestore";
import { doc, setDoc } from '@firebase/firestore';
import admin from "firebase-admin";
const serviceAccount = require('foo')
const app = initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: `bar`
})
const database = getFirestore(app)
// everything works as expected up to this point, let's set a doc now...
setDoc(doc(database, 'baz', 'qux'), {
quux: 'corge'
})
The issue is that the type is not correct, and even if we cast it to something else, we get this error and the operation fails:
FirebaseError: Expected first argument to collection() to be a CollectionReference...
My question
Is firebase-admin@10.0.0
not supposed to be used with modular setDoc
or doc
?
What is the best way to approach this? We have an entire codebase and we do not want to migrate/downgrade everything so that it is on par with v8, we want to use v9 syntax as we do with the regular firebase-app