Skip to content

@angular/fire: ERROR FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore #3435

@vks9009

Description

@vks9009

Version info

Angular: 16.2.0

Firebase: 10.3.1

AngularFire: 7.6.1

Other (e.g. Ionic/Cordova, Node, browser, operating system):
Google Chrome
Windows 11
Node v18.16.1

How to reproduce these conditions

I am getting error when trying to read firestore collection. I

I have implemented the code with AngularFire Cloud Firestore document. https://github.com/angular/angularfire/blob/master/docs/firestore.md#cloud-firestore
Failing test unit, Stackblitz demonstrating the problem

Steps to set up and reproduce
app.module.ts

imports: [
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAnalytics(() => getAnalytics()),
    provideAuth(() => getAuth()),
    provideDatabase(() => getDatabase()),
    provideFirestore(() => getFirestore()),
    provideFunctions(() => getFunctions()),
    provideMessaging(() => getMessaging()),
    providePerformance(() => getPerformance()),
    provideRemoteConfig(() => getRemoteConfig()),
    provideStorage(() => getStorage())
  ]

auth.service.ts

import { Inject, Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { Auth, authState, signInWithEmailAndPassword, 
    createUserWithEmailAndPassword, onAuthStateChanged, 
    signOut, GoogleAuthProvider,
    user} from "@angular/fire/auth";
import { Firestore, collectionData, collection, getFirestore, getDocs  } from "@angular/fire/firestore";
import { AngularFireAuth,  } from '@angular/fire/compat/auth';
import { Router } from '@angular/router';

@Injectable({ providedIn: 'root' })
export class AuthService {
    userData: any; 
    UsersCollection: any;
    UsersData: any; 

    constructor( 
        private auth: Auth,
        private firestore: Firestore,
        private afAuth: AngularFireAuth,
        private router: Router
        ) {
           console.log(this.firestore);
            const itemCollection = collection(this.firestore, 'Classes');
    }
}

Sample data and security rules

Debug output

** Errors in the JavaScript console **

ERROR FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore main.ts:13 FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

** Output from firebase.database().enableLogging(true); **

** Screenshots **
image

Expected behavior

Actual behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions