Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda