2

I want to generate 6 digit unique number in Firbase (unique must) enter image description here

above attendeeCode should be unique on every new attendess entry

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

Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150

1 Answers1

3

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

theblindprophet
  • 7,767
  • 5
  • 37
  • 55
  • Thank you so much but currently I have already done like that, but although posted question might be I get something new from someone :) – Siddhpura Amit Jun 06 '17 at 12:27
  • This won't work as expected because client can work offline too, the count change in server may not be realtime so it can be conflict – PRAJIN PRAKASH Dec 30 '21 at 04:13