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

480
Visualizações
V 9 FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

can't add new document to firestore I am new to vue and firestore. This is my config file. [this is my DataServices directory>>C:\Users\LENOVO\Desktop\covidcare-ytu-clinic\src\Services\DataServices.js][1]This is vue directory>>C:\Users\LENOVO\Desktop\covidcare-ytu-clinic\src\views\ClientForm.vue

firebase.js

import { initializeApp } from "firebase/app"
import { getAuth, connectAuthEmulator } from "firebase/auth"
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"

const firebaseConfig = {
  apiKey: 
  projectId: "covidcare-ytu-clinic",
  
}

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig)

const db = getFirestore()

connectFirestoreEmulator(db, "localhost", 8081)

const auth = getAuth(firebaseApp)
connectAuthEmulator(auth, "http://localhost:9099")

export default { db, auth }

This is my Dataservice.js

import { db } from "@/firebase"
import { addDoc, collection } from "firebase/firestore"
class dataService {
  /* async getAll() {
    const querySnapshot = await getDocs(collection(db, "clients"))
    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=> ", doc.data())
    })
  }*/
  async create(data) {
    try {
      const docRef = await addDoc(collection(db, "cli"), data)
      console.log("Document written with ID: ", docRef.id)
    } catch (e) {
      console.error("Error adding document: ", e)
    }
  }
  /*
  update(id, data) {
    return db.collection("clients").doc(id).updateDoc(data)
  }
  delete(id) {
    return db.collection("clients").doc(id).delete()
  }*/version-8 firebase
}
export default new dataService()

Here is my firebase error ..I couldn't add any document to my firestore.This is stacking me so long .


DataServices.js:15 Error adding document:  FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I found the answer .When somebody face this kind of problems like me , i hope this helpful . i delete default in config file where i should write export { db ,auth} .

about 4 years ago · Juan Pablo Isaza Relatório

0

In Dataservice.js, try using relative path for importing db:

// Remove this
// import { db } from "@/firebase"

// Try this
import { db } from "../../firebase" // relative path to config file
about 4 years ago · Juan Pablo Isaza 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