Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

469
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda