Generate sequential key with firebase

Asked

Viewed 2,048 times

1

Good morning ! I am working on an app that saves some user activities and I have a problem to save these activities generating sequential numbers, here is the environment: I have the user logged in, it will create a new activity and when saving it in the ACTIVITIES node it receives the id 1 number, then user B saves another activity in another cell that will receive id 2, then user A saves a new one now with id 3... and so on... Thanks in advance!

  • then, do the following, collect the desired firebase information if it acts, in case it is the whole type id, and add 1 every time you add something new.

  • 1

    You can save the id information of the last activity as @Matheus said and use set instead of push to save the data. With set your path should already include the id that will be used. Ex: fb.ref('atividades/${lastId+1}/').set({atividade});

1 answer

-1

Use the method push() he makes in sequence his data

database.child("dados").push().setValue(objeto);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.