Ad

Get Data From A Collection With Firestore Ionic 4

- 1 answer

I would like to get unique data from doc from a collection with firebase firestore

So i use to get all data:

 ngOnInit() {

return this.firestore.collection('users').snapshotChanges()



.subscribe(data => {


  console.log(data);
  this.utilisateurs = data;
  console.log(this.passided);

});


}

and this to get unique id :

this.passided = this.navParams.get('id');

And i tried to do this :

return this.firestore.collection('users').doc(this.passided).snapshotChanges()

firestore

but don't work, can you help me please?

Ad

Answer

snapshotChanges() is a method inside class AngularFirestoreCollection which returns an Observable of data as a DocumentChangeAction.

If you want to manipulate documents, then you can use the following methods:

set(data: T) - Destructively updates a document's data.

update(data: T) - Non-destructively updates a document's data.

delete() - Deletes an entire document. Does not delete any nested collections.


Therefore, this this.firestore.collection('users').doc(this.passided).snapshotChanges() wont work since snapshotChanges() is not a method in the document.ts

For reference: https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md#snapshotchanges

https://github.com/angular/angularfire2/blob/master/src/firestore/collection/collection.ts#L97

Ad
source: stackoverflow.com
Ad