gpt4 book ai didi

firebase - 在 Firebase 中,push 和 childByAutoId 有什么区别

转载 作者:行者123 更新时间:2023-12-02 21:33:52 24 4
gpt4 key购买 nike

在 Firebase 中,如果我想创建具有唯一 ID 的子节点,我有两个选择:

推():

Use the push() method to append data to a list in multiuser applications. The push() method generates a unique ID every time a new child is added to the specified Firebase reference. By using these auto-generated keys for each new element in the list, several clients can add children to the same location at the same time without write conflicts. The unique ID generated by push() is based on a timestamp, so list items are automatically ordered chronologically.

childByAutoId:

childByAutoId generates a new child location using a unique key and returns a FIRDatabaseReference to it. This is useful when the children of a Firebase Database location represent a list of items. The unique key generated by childByAutoId: is prefixed with a client-generated timestamp so that the resulting list will be chronologically-sorted.

有什么区别?

最佳答案

没关系,看起来它们是相同的,只是它们迎合不同的平台:

Save Data on IOS

childByAutoId : Add to a list of data. Every time you call childByAutoId, Firebase generates a unique ID, such as user-posts/<user-id>/<unique-post-id>.

Save Data on Web

push() : Add to a list of data. Every time you call push(), Firebase generates a unique ID, such as user-posts/<user-id>/<unique-post-id>.

关于firebase - 在 Firebase 中,push 和 childByAutoId 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com