Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
Firebase is expecting the first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

I am trying to initialize the Admin SDK in a NextJS app. I have initialized the app as so:

import { getFirestore } from '@firebase/firestore';
import admin from 'firebase-admin';

if (!admin.apps.length) {
  admin.initializeApp({
    credential: admin.credential.cert({
      project_id: process.env.NEXT_PUBLIC_PROJECT_ID,
      private_key: process.env.FIREBASE_PRIVATE_KEY,
      client_email: process.env.FIREBASE_CLIENT_EMAIL
    })
  });
}

export default getFirestore();

and then try to use the database in the following code snippet:

import { getDocs, collection } from '@firebase/firestore';
import db from '@/lib/firebase-admin';

export default async (_, res) => {
  let sites = [];

  const querySnapshot = await getDocs(collection(db, 'sites'));
  querySnapshot.forEach((doc) => {
    sites.push(doc.id, ...doc);
  });

  res.status(200).json(sites);
};

But I am presented with the following error: Next JS Firebase Error

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

I am using the Web V9 (module) components of Firebase, and have yet to figure out why I am getting this error. Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!