Skip to content
Advertisement

FirebaseError: Expected type ‘Tc’, but it was: a custom Ac object

I’m trying to access all documents from my firestore collection

  const app = initializeApp(firebaseConfig);
  const db = getFirestore(app);


  async function getTodos() {
        try {
            const todoRef = collection(db, 'todos');
            let allTodos = await getDoc(todoRef);
            console.log(allTodos)

        } catch (err) {
            console.log(err)
        }
    }

but it’s throwing this err FirebaseError: Expected type 'Tc', but it was: a custom Ac object

Advertisement

Answer

The getDoc() method is used to get a single document and takes a DocumentReference as a parameter. Here todoRef is a CollectionReference and to fetch multiple documents you must use getDocs() instead:

const todoRef = collection(db, 'todos');
let allTodos = await getDocs(todoRef);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement