What is snapshotchanges in firestore

后端 未结 3 1821
悲哀的现实
悲哀的现实 2020-12-10 03:48

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

  initializeItems(){
this.travelList$ = this.plsdala.getTravelLi         


        
3条回答
  •  生来不讨喜
    2020-12-10 04:34

    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.

提交回复
热议问题