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

197
Views
Why am I getting TypeErrors 'x' is not a function with firebase collection query?

My js file is correctly entered in the DOM, I have initailized firebase in the firebase.js file. Why am I getting a

TypeError 'collection(...).doc is not a function' -

The collection query is taken directly from the firebase docs site, I don't understand how this could be a type error.. Any ideas?

import { app } from "./firebase";
import { getFirestore, doc, collection } from "firebase/firestore";

const db = getFirestore(app);

// get data

const docRef = collection(db, 'posts').doc('ARt1ctrEjweKEd4gmgCr');
await docRef.get();
if (!doc.exists) {
  console.log('No such document!');
} else {
  console.log('Document data:', doc.data());
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The doc() is top level function in Modular SDK and not a method on collection(). Try:

import { getFirestore, doc, getDoc } from "firebase/firestore";

// Creating DocumentReference
const docRef = doc(db, 'posts', 'ARt1ctrEjweKEd4gmgCr');

const docSnap = await getDoc(docRef);

if (!doc.exists) {
  console.log('No such document!');
} else {
  console.log('Document data:', doc.data());
}

Also checkout: Firestore: What's the pattern for adding new data in Web v9?

about 4 years ago · Juan Pablo Isaza Report
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!