Auto increment a value in firebase with javascript

后端 未结 5 2108
野性不改
野性不改 2020-12-03 14:52

Hello I\'m working on some firebase project and i can save my datas via javascript into firebase database. But i couldn\'t figure it out to auto increment child value (my ch

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 15:11

    Firebase recommends using distributed counters: https://firebase.google.com/docs/firestore/solutions/counters

    For the document that requires the counter, you'd initialize a subcollection of, say, 10 documents and run transaction increments on a random shard whenever you need a counter incremented.

    Then you'd query the collection of shards and sum their counters.

提交回复
热议问题