I\'m a newbie in firebase.
How do I get through this below rule?
service cloud.firestore {
match /databases/{database}/documents {
match /{document
I was able to solve the problem by switching from Cloud Firestore to Realtime Database, and then changing the rule. (After I've changed this, there was no more error showing!)
You should check in your Angular NgModule and components if you are using "Realtime Database" or "Cloud Firestore". See diferences using "angularfire2":
REALTIME DATABASE
@NgModule({
...
imports: [
AngularFireDatabaseModule,
...
],
providers: [
AngularFireDatabase,
...
]
})
@Component({...})
export class FirestoreComponent{
constructor(private realtimeDb:AngularFireDatabase, ...) {
this.locations = realtimeDb.list('locations').valueChanges();
}
...
}
CLOUD FIRESTORE
@NgModule({
...
imports: [
AngularFirestoreModule,
...
]
})
@Component({...})
export class FirestoreComponent{
constructor(private firestore:AngularFirestore, ...) {
this.locations = firestore.collection('locations').valueChanges();
}
...
}
For others struggling with this problem, the proper solution is to change the false
in
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
To true
while testing. Don't forget to add additional security when going live with your project!
Because your method query the Firebase not Cloud Firestore so you should use this method :
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("YourCollectionName").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
dont forget this :
implementation 'com.google.firebase:firebase-firestore:17.0.1'