自定义ID到Firebase实时数据库 [英] Customize IDs into Firebase Realtime Database
问题描述
我正在使用集成在移动应用程序和Web面板中的Firebase实时数据库.默认情况下,实时数据库上的唯一ID会以以下格式生成: -Lup7ey2xRPO9Owm67xM
I'm using Firebase Realtime Database integrated in a mobile app and web panel. By default, a unique ID on Realtime DB is generated on this format: -Lup7ey2xRPO9Owm67xM
通过Firebase面板创建新注册时,我可以使用GUID自定义唯一ID.
When creating new register through the Firebase panel, i can customize the unique id with GUID.
{
"0a921e40-5959-43bc-b2be-a65f6712288d": {
"name": "Test"
},
}
但是,在使用Postman或在我的后端调用Rest API之后,默认情况下会在Firebase上生成唯一ID:
However, after call Rest API, with Postman or on my backend, the unique ID is generated by default on Firebase:
{
"-LupIEooOPXAzbc--dB_": {
"name": "Test 2"
},
}
是否有可能配置Firebase以GUID格式生成唯一ID?要替换默认格式吗?
Is it a possible configure Firebase do generate unique ids on format GUID? Replacing default format?
推荐答案
The documentation for the REST API says that using POST is the equivalent of a push operation, which always generates that random push ID. If you want to specify your own name for the node to add, you should be using a PUT request instead and using the client-generated ID in the path for the update.
这篇关于自定义ID到Firebase实时数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!