Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is snapshotchanges in firestore

this function is called by the constructor. can someone explain in depth to me what it does?

  initializeItems(){
this.travelList$ = this.plsdala.getTravelList()
.snapshotChanges()
.map(
  changes => {
    return changes.map(c=>({
      key: c.payload.key, ...c.payload.val()
    })).slice().reverse();

   //to reverse order
  });

}
like image 862
Jennica Avatar asked Feb 04 '18 13:02

Jennica


People also ask

What is snapshotChanges?

snapshotChanges() Metadata provides you the underyling DocumentReference , document id, and array index of the single document. Having the document's id around makes it easier to use data manipulation methods.

Is firestore key value store?

In Firestore, you typically have a single collection and multiple documents in that collection. To use Firestore as a key/value store for Workflows, one idea is to use the workflow name as the collection name and use a single document to store all the key/value pairs.

What is reference type in firestore?

firestore. DocumentReference. < T > A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location.

What is AngularFirestoreDocument?

The AngularFirestoreDocument service is a wrapper around the native Firestore SDK's DocumentReference type. It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an @Injectable() .


1 Answers

It is current state of firestore collection. It returns an Observable of data. You would use it whenever you want to be able to get also your metadata as documentID as opposed to using for example valueChanges() which returns Observable containing data saved in document only. It does not contain metadata.

This means that you would usually use valueChanges() to get data and snapshotChanges() whenever you might need metadata, eg. deleting or updating document.

Your code basically gets data and metadata of document and extracts just data from it. Then it reverses the data to go from end of the collection to the beginning.

like image 142
Robo Bayer Avatar answered Oct 04 '22 04:10

Robo Bayer