0

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • `@firebase/firestore` is the Firebase JS (client-side) SDK. You cannot use that with the Admin SDK. The server-side Firestore library doesn't provide a modular API surface yet. – Hiranya Jayathilaka Dec 07 '21 at 19:36
  • Hi, You might want to take a look at these posts [cant-add-data-to-firestore-collection)](https://stackoverflow.com/questions/69531792/cant-add-data-to-firestore-collection) and [firebase-expected-first-argument-to-collection](https://stackoverflow.com/questions/69889158/react-native-firestore-firebase-expected-first-argument-to-collection-to-be-a) – Mathew Bellamy Dec 07 '21 at 22:12

0 Answers0