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

116
Views
db.collection("articles").add results in ".default.collection is not a function"

Essentially I want to add a collection called "articles" with the following actors and store it in firebase.

I followed the doc for uploading files to firebase. I was reading the doc for adding data to firebase but it was a bit confusing and not sure how to implement it.

index.js (to view the other top half, here)

...
() => {
   getDownloadURL(upload.snapshot.ref).then((downloadURL) => {
    db.collection("articles").add({
      actor: {
        description: payload.user.email,
        title: payload.user.displayName,
        date: payload.timestamp,
        image: payload.user.photoURL,
        },
        video: payload.video,
        sharedImg: downloadURL,
        comments: 0,
        description: payload.description,
       });
   });
}

However, whenever I run this code, I get "Unhandled Rejection (TypeError): firebase__WEBPACK_IMPORTED_MODULE_0_.default.collection is not a function."

firebase.js

import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider } from 'firebase/auth';
import { getStorage } from "firebase/storage";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
...
}

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);
const auth = getAuth();
const provider = new GoogleAuthProvider();
const storage = getStorage(firebaseApp);
  
export { auth, provider, storage };
export default db;

Any advise as to what is going wrong? Thanks!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Same as on your previous question, since you're using the v9 syntax to import specific functions, you can no longer call methods on db or a CollectionReference.

The equivalent of your snippet in the v9 modular syntax is:

const collectionRef = collection(db, "articles")
addDoc(collectionRef, { ... })

I strongly recommend that you spend some time in the Firebase documentation on writing data and in the upgrade guide to get familiar with how the syntax in your existing code maps to the new syntax.


If you don't want to upgrade your code, you can also consider using the compat paths of the v9 SDKs.

about 4 years ago · Santiago Gelvez 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!