问题描述
我想在Firbase中生成6位唯一数字(必须为唯一)
I want to generate 6 digit unique number in Firbase (unique must)
在每个与会者新条目上,与会者代码上方应该唯一
above attendeeCode should be unique on every new attendess entry
我是Firebase的新手,我已经搜索了很多但找不到
I am new in firebase and I have searched alot but could not find
推荐答案
创建一个六位数字,该数字与与会者
中的第n个条目相对应.然后在其他地方跟踪该数字.
Create a six digit number that corresponds to the nth entry into attendees
. And then keep track of that number elsewhere.
您可能会在其他问题中发现Firebase仍然不支持COUNT或LENGTH个查询.
You can find in other questions that Firebase still does not support COUNT or LENGTH queries.
创建一个名为/meta-data
(任意)的路径并保存当前与会者的数量:
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.
一个新选项: Firebase云功能
此功能仍处于测试阶段,但取得了一定的成功.他们在此处提供了此功能的示例:
This is still in beta, but is having fair success. They provided and example of this functionality here:
这篇关于在Firebase中生成6位唯一编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!