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

309
Views
Read Collection in firebase from vue js

I am trying to read a collection with specific name from firebase firestore, but I get an error which I couldn't find answer for it. Here you can see my boot file:

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
import { collection, query, where, doc, getDoc } from "firebase/firestore";



const firebaseApp = initializeApp({
    apiKey: "####",
    authDomain: "####",
    projectId: "####",
});


const db = getFirestore();
const auth = getAuth();
const createUser = createUserWithEmailAndPassword();

export default {db, auth, createUser};

Here is my script tag in .vue file:

<script>
import { collection, getDocs } from "firebase/firestore";
import db from "src/boot/firebase"

export default {
  setup() {
    return {
      waitingList: {},
    };
  },
  created() {
    const querySnapshot = await getDocs(collection(db, "waitingList"));
    querySnapshot.forEach((doc) => {
      // doc.data() is never undefined for query doc snapshots
      console.log(doc.name, " => ", doc.data());
    });
  },
};
</script>

and here you can see the list of errors I got:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'tenantId')

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The imported db would be an object containing instances of Firestore and Auth. Try changing your import as shown below:

import { db } from "src/boot/firebase"
// instead of import db from "..." 

export default {
  setup() {
    return {
      waitingList: {},
    };
  },
  async created() {
    const querySnapshot = await getDocs(collection(db, "waitingList"));
    querySnapshot.forEach((doc) => {
      console.log(doc.name, " => ", doc.data());
    });
  },
};

Also change export default { db } to export { db } in the boot 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!