add data in already existing key in firebase database code example

Example 1: add to firebase database

db.collection("cities").add({
    name: "Tokyo",
    country: "Japan"
})
.then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
    console.error("Error adding document: ", error);
});

Example 2: how to go through child in firebase Unity

void InitializeFirebase() {


    FirebaseApp app = FirebaseApp.DefaultInstance;
    app.SetEditorDatabaseUrl ("https://slol.firebaseio.com/");

    FirebaseDatabase.DefaultInstance
        .GetReference ("Products").OrderByChild ("category").EqualTo("livingroom")
        .ValueChanged += (object sender2, ValueChangedEventArgs e2) => {
        if (e2.DatabaseError != null) {
            Debug.LogError (e2.DatabaseError.Message);
        }


        if (e2.Snapshot != null && e2.Snapshot.ChildrenCount > 0) {

            foreach (var childSnapshot in e2.Snapshot.Children) {
                var name = childSnapshot.Child ("name").Value.ToString (); 

                text.text = name.ToString();
                Debug.Log(name.ToString());
                //text.text = childSnapshot.ToString();

            }

        }

    };
}

Tags:

Misc Example