Adding fields to existing database

1,594 views
Skip to first unread message

Walid Al-Turk

unread,
Aug 17, 2015, 11:14:39 AM8/17/15
to Firebase Google Group
Hello all, 

I am new to Firebase and wonder if there is a way to add a field or fields to an existing database. Lets say I have a database with "chat" child. the chat child has two fields username and message. after adding several records I want to add a field "messagedate" to all objects in the chat database child. How can I do this?

Thanks 

Frank van Puffelen

unread,
Aug 17, 2015, 12:05:49 PM8/17/15
to Firebase Google Group
Hi Walid,

Something like this would do the trick:

    var ref = new Firebase('https://yours.firebaseio.com/chat');
    ref.on('child_added', function(snapshot) {
        snapshot.ref().update({ messagedate: Date.now() });
    });

Kato Richardson

unread,
Aug 17, 2015, 12:34:34 PM8/17/15
to Firebase Google Group
An additional note that may be of use: Puf's example would be equivalent to this set, when working with a single child key:

snapshot.ref().child('messagedate').set( Firebase.ServerValue.TIMESTAMP );

Where the update() would be more useful for working with multiple child keys. Hopefully that helps to outline the difference between set/update and where both may be useful.

Also I'd prefer Firebase.ServerValue.TIMESTAMP for most date-related ops.

☃, Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/dd2d7e9e-78a8-46d1-8d72-adf60c5b50e5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages