Hello, I am working on a firebase project, and I can save my data through javascript in a firebase database. But I could not figure out how to automatically increase the child value (my child value is duyuru, you can see the details below) of my database. I am sharing my code below, you can give me hints to solve this problem.
<script> // Initialize Firebase var config = { apiKey: "sample1", authDomain: "sample2", databaseURL: "sample3", storageBucket: "sample4", }; firebase.initializeApp(config); var database = firebase.database(); firebase.initializeApp(config); var database = firebase.database(); function writeUserData(userId, name, email, imageUrl) { var kategori1 = document.getElementById("kategori").value; var duyuru1 = document.getElementById("duyuru").value; var name1 = document.getElementById("name").value; var email1 = document.getElementById("email").value; var imageUrl1 = document.getElementById("imageUrl").value; firebase.database().ref(kategori1 +"/" + duyuru1).set({ username: name1, email: email1, profile_picture : imageUrl1 }); } </script>
and the output is as follows
{ "duyuru1": { "email": "kjfdlkl", "profile_picture": "dsfsd", "username": "meraha" } }
I want to output such data:
{ "duyuru1": { "email": "kjfdlkl", "profile_picture": "dsfsd", "username": "meraha" }, "duyuru2": { "email": "kjfdlkl", "profile_picture": "dsfsd", "username": "meraha" } }
The duyuru (child value) section should be auto incremented, this is what I wanted. thank you for your responses
source share