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

365
Views
can you help me solve this collection.get() function error?

I was trying to use a database in my project, so i imported 'collection' to use it this is my code:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword, signOut, signInWithEmailAndPassword, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-auth.js";
import { getFirestore, collection } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js";

const firebaseConfig = {
  apiKey: "AIzaSyC3GLIN5TBmCDoTfy0dEOgOdvVvqNw-ric",
  authDomain: "auth-project-38aaa.firebaseapp.com",
  projectId: "auth-project-38aaa",
  storageBucket: "auth-project-38aaa.appspot.com",
  messagingSenderId: "431888894254",
  appId: "1:431888894254:web:71bb9b250fbb8a21edd2bf",
  measurementId: "G-6BBPCJ3814"
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);

// get data
collection(db, 'guides').get().then(snapshot => {
    console.log(snapshot.docs);
});

but instead of showing me the 'snapshot.docs' in the console it gives me this message:

auth.js:20 Uncaught TypeError: collection(...).get is not a function
    at auth.js:20

please help me to solve this problem.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're importing the new modular/functional SDK, where the equivalent of collectionRef.get() is actually:

getDocs(collection(db, 'guides')).then(snapshot => {
  ...

The Firebase documentation itself has all been updated to contain both the older snippets, and snippets for the new API, such as in this case the documentation on getting multiple documents.

But if you're new to Firebase and using code from other places, those might not have both snippets styles yet. In that case it might be easier to start by importing the compat libraries from the new SDKs, while you're figuring out how everything works. If you just want to do that for Firestore, it'd be:

import 'firebase/compat/firestore';
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!