Pierre Torres
Pierre Torres

Reputation: 287

Get data from a collection with firestore ionic 4

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?

Upvotes: 1

Views: 2990

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

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

Upvotes: 1

Related Questions