Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  193] [ 3]  / answers: 1 / hits: 53159  / 8 Years ago, sun, august 21, 2016, 12:00:00

Hello I'm working on some firebase project and i can save my datas via javascript into firebase database. But i couldn't figure it out to auto increment child value (my child value is duyuru, you can see the details in the below) of my database. I'm sharing my code in below can you give me hints to solve this issue.



  <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 out is like this



{
duyuru1: {
email: kjfdlkl,
profile_picture: dsfsd,
username: meraha
}
}


I want to output data like;



{
duyuru1: {
email: kjfdlkl,
profile_picture: dsfsd,
username: meraha
},

duyuru2: {
email: kjfdlkl,
profile_picture: dsfsd,
username: meraha
}
}


duyuru (child value) section should be auto increment, That's what i wanted for. Thank you for your answers


More From » firebase

 Answers
43

Firebase has no auto-incrementing keys, since those don't work well in massively multi-user systems where clients can be offline for prolonged periods.



Instead, Firebase has its own type of auto-generated keys called push IDs. These push IDs have the same important properties of sequences in many relational databases: they are ordered and sequential. But in addition, they can be calculated client-side, even when the client is not connected to the Firebase servers.



See the Firebase documentation on saving data in lists, this legacy blog post on why arrays don't work well in Firebase and this post on how push ids work.


[#60969] Thursday, August 18, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseb

Total Points: 252
Total Questions: 96
Total Answers: 106

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
analiseb questions
;