I have a firebase list, and I'm adding a new node. When using $add it
creates a new PushId for my new key, but I need to specify my own key.

I know I can get this to work using $update(key, obj), but it just seems
like $add should support the key. I just want to make sure I'm not doing
something wrong.

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/b9577668-505c-42ad-aff1-e4c84e0ef257%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Kato Richardson at Feb 26, 2015 at 6:16 am
    Nick,

    You can create a record at any time by simply inserting the data directly
    into Firebase:

    var ref = new Firebase(...);
    var syncArray = $firebase(ref).$asArray();
    ref.child( myOwnKey ).set( jsonData ); // will be synced into syncArray
    automagically

    You can also call $save on any object which returns a valid key according
    to $keyAt (i.e. anything that has a $id). So you could, for example, do
    something like:

    var rec = { $id: myOwnKey, foo: 'bar' };
    syncArray.push(rec);
    syncArray.$save(rec);

    The problem with this is that the record will not be sorted properly into
    the array, so it becomes a fairly complex dance to get everything in
    matching order. It's probably simplest here to simply drop to the SDK level
    as in the first example.

    Also keep in mind that, generally speaking, adding records to a collection
    from the client, using a custom id, can be error prone since we are working
    in collaborative, real-time data, and that those records don't naturally
    sort chronologically, and can't be guaranteed unique. Push ids are
    generally best here.

    Cheers,
    Kato

    On Wed, Feb 25, 2015 at 5:15 AM, Nick Caruso wrote:

    I have a firebase list, and I'm adding a new node. When using $add it
    creates a new PushId for my new key, but I need to specify my own key.

    I know I can get this to work using $update(key, obj), but it just seems
    like $add should support the key. I just want to make sure I'm not doing
    something wrong.

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/b9577668-505c-42ad-aff1-e4c84e0ef257%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/b9577668-505c-42ad-aff1-e4c84e0ef257%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CADypTEZ6T5OucGVWfOQtVBKpqBGGDmNMzH7UxSH3%3D6cHNqHHLQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedFeb 25, '15 at 8:10p
activeFeb 26, '15 at 6:16a
posts2
users2

2 users in discussion

Kato Richardson: 1 post Nick Caruso: 1 post

People

Translate

site design / logo © 2021 Grokbase