2

I have the following json, which I save to firebase using $push.

{"eventId" : x, eventName : "nameofevent", speakers: [101, 102]}

How do I store a unique integer (int32) in eventId?

I would use the key produced by the reference but it has to be an integer.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Shavin Peiris
  • 81
  • 1
  • 9
  • You can't use timestamp in miliseconds? – Ami Hollander Jun 30 '16 at 05:54
  • @AmiHollander I've been using timestamp, but it produces a 13 digit integer which is too long. I need it to be int32 specifically(10 digits).. :/ An open source app I'm building consumes rest api, which I produce and it requires the id to be of size int32. – Shavin Peiris Jun 30 '16 at 06:03
  • You can always store a `unique id` on the database and read it when push data. But I think it's not the best solution. – Ami Hollander Jun 30 '16 at 06:12
  • @AmiHollander I would but it's not secure. – Shavin Peiris Jun 30 '16 at 06:15
  • To generate a 10 digit integer, there are probably some solutions out there. Then to guarantee its uniqueness, see http://stackoverflow.com/questions/25294478/how-do-you-prevent-duplicate-user-properties-in-firebase or http://stackoverflow.com/questions/29970681/enforcing-unique-usernames-with-firebase-simplelogin – Frank van Puffelen Jun 30 '16 at 13:37
  • 1
    `ID`s are usually simply consecutive numbers, so `ID = lastID + 1`, where `lastID` is the largest ID yet. – XCS Jun 30 '16 at 13:41

0 Answers0