Firebase: Get New Child Added

前端 未结 1 514
甜味超标
甜味超标 2021-01-07 11:48

When my application starts I do an initial fetch to Firebase to pull down all my data. When I later add data to my Firebase, I only want it to get the new child that\'s been

1条回答
  •  醉梦人生
    2021-01-07 12:11

    1. If you need both new data and subsequent data, use child_added. It will fire immediately for all existing children and subsequently for any child that is added.

    2. if you only want new data, add a timestamp to your children and ref.orderByChild('timestamp').startAt(Date.now())

    3. If you need both new data and subsequent data, but want to treat the initial children differently: use child_added and value as you do now.

    Also see: How to only get new data without existing data from a Firebase?

    0 讨论(0)
提交回复
热议问题