While working on my Angular CRUD project with Firestore integration, I encountered an issue. Whenever I try to add a new object to the database, I receive the following error message: "ERROR FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore." Despite carefully reviewing my code, I am unable to determine what is causing this error. My project uses Angular 16, Firebase 10.3.1, and angular/fire 7.5.0.
ERROR FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
import { Injectable } from '@angular/core';
import { Firestore, collection, addDoc } from '@angular/fire/firestore';
@Injectable({
providedIn: 'root',
})
export class TesteService {
constructor(private firestore: Firestore) {}
addData(user: any) {
const collectionInstance = collection(this.firestore, 'users');
addDoc(collectionInstance, user)
.then(() => {
console.log('It Worked!');
})
.catch((error) => {
console.log('Something went wrong', error);
});
}
}
I suspect that this issue may be due to changes in the recent versions of the libraries being used.