Customize IDs into Firebase Realtime Database [duplicate]

ε祈祈猫儿з 提交于 2021-02-05 12:09:41

问题


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

When creating new register through the Firebase panel, i can customize the unique id with GUID.

{
  "0a921e40-5959-43bc-b2be-a65f6712288d": {
    "name": "Test"
  },
}

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"
  },
}

Is it a possible configure Firebase do generate unique ids on format GUID? Replacing default format?


回答1:


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.



来源:https://stackoverflow.com/questions/59098699/customize-ids-into-firebase-realtime-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!