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

466
Views
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 answers
Answer question

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 Report

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 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!