Generate 6 digit unique number in Firebase

社会主义新天地 提交于 2021-01-28 05:31:42

问题


I want to generate 6 digit unique number in Firbase (unique must)

above attendeeCode should be unique on every new attendess entry

I am new in firebase and I have searched alot but could not find


回答1:


Create a six digit number that corresponds to the nth entry into attendees. And then keep track of that number elsewhere.

You can find in other questions that Firebase still does not support COUNT or LENGTH queries.

Create a path called /meta-data (arbitrary) and save the number of current attendees:

meta-data: {
    num_of_attendees: "000000" // parse this client side and send back padded string to keep 6 characters
}

Grab the value every time you add an attendee, increment it, and send it back. This keeps you from grabbing a list of all attendees and getting the length client-side.

A new option: Firebase Cloud Functions

This is still in beta, but is having fair success. They provided and example of this functionality here:

functions-sample



来源:https://stackoverflow.com/questions/44389421/generate-6-digit-unique-number-in-firebase

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