Two sets of information: users and contacts.

    - The user can add contacts to the general contacts set, which is shared
    among all users.
    - The contacts set will eventually be quite, quite large.
    - The user uploads sets of contacts from an external source, so I get
    them all at once.
    - A new contact record will be created for every single phone number,
    which will be used as the key for the object. (e.g., 16125555555)

So, here's the question: I'd ideally like to take the whole batch of new
contacts, standardize the number formats, rip out the data I need, and
create the objects in one pass client side and then send the whole set back
to firebase. But the catch is that some of those contacts may already
exist, so if I just do a simple "set", I'll overwrite the existing contact.
I could cycle through each one and do a set at the specific key, but not
only will that be costly, but I would have to go one level lower to ensure
no data is overwritten (if they key is the same, I want to *add* data to
the key, not overwrite existing properties). I could use update, but then I
don't get the new ones. I could pull down the whole contact data set,
iterate through it client side, and send it back all together but that's
going to be slow both on the network (the data sets can be quite large) and
client side (a lot of processing).

Ideally, there would be some setOrUpdate function... but I don't think that
exists.

Thoughts?

--
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/c47a96c7-0c0e-4b74-a534-661eca96ab87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jacob Wenger at Aug 6, 2014 at 6:10 pm
    Hey Matt,

    I do think that update()
    <https://www.firebase.com/docs/web/api/firebase/update.html> is what you
    want here. You main concern appears to be "*I could use update, but then I
    don't get the new ones*." That is not true. update() essentially works by
    calling set() on each of the named children, and no others. So it won't
    overwrite existing children, unless they are part of the object you send
    into update(). Non-existing children which are in the data you send into
    update() *do* get added. The only catch with update() to remember is that
    it is not recursive. Like I said, it is really just calling set() on all
    named children at the root of the object you send it.

    If you haven't already, read through the docs on update()
    <https://www.firebase.com/docs/web/api/firebase/update.html>.

    If you still really don't think this will work for your use case, let me
    know and I can throw out some more suggestions.

    Jacob

    On Wed, Aug 6, 2014 at 9:34 AM, Matt Martin wrote:

    Two sets of information: users and contacts.

    - The user can add contacts to the general contacts set, which is
    shared among all users.
    - The contacts set will eventually be quite, quite large.
    - The user uploads sets of contacts from an external source, so I get
    them all at once.
    - A new contact record will be created for every single phone number,
    which will be used as the key for the object. (e.g., 16125555555)

    So, here's the question: I'd ideally like to take the whole batch of new
    contacts, standardize the number formats, rip out the data I need, and
    create the objects in one pass client side and then send the whole set back
    to firebase. But the catch is that some of those contacts may already
    exist, so if I just do a simple "set", I'll overwrite the existing contact.
    I could cycle through each one and do a set at the specific key, but not
    only will that be costly, but I would have to go one level lower to ensure
    no data is overwritten (if they key is the same, I want to *add* data to
    the key, not overwrite existing properties). I could use update, but then I
    don't get the new ones. I could pull down the whole contact data set,
    iterate through it client side, and send it back all together but that's
    going to be slow both on the network (the data sets can be quite large) and
    client side (a lot of processing).

    Ideally, there would be some setOrUpdate function... but I don't think
    that exists.

    Thoughts?

    --
    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/c47a96c7-0c0e-4b74-a534-661eca96ab87%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/c47a96c7-0c0e-4b74-a534-661eca96ab87%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/CAKZX5-5CdbO%3DUcGUVX0oeFwHK8Vxj4UwNkv-cxoX5N4iFxQTEg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Matt Martin at Aug 6, 2014 at 10:57 pm
    Thanks for the response!

    This should work well. I read the docs on update(), but for some reason I
    interpreted it as not adding new ones. Glad that's not the case!

    Thanks again.
    On Wednesday, August 6, 2014 11:10:52 AM UTC-7, Jacob Wenger wrote:

    Hey Matt,

    I do think that update()
    <https://www.firebase.com/docs/web/api/firebase/update.html> is what you
    want here. You main concern appears to be "*I could use update, but then
    I don't get the new ones*." That is not true. update() essentially works
    by calling set() on each of the named children, and no others. So it
    won't overwrite existing children, unless they are part of the object you
    send into update(). Non-existing children which are in the data you send
    into update() *do* get added. The only catch with update() to remember is
    that it is not recursive. Like I said, it is really just calling set() on
    all named children at the root of the object you send it.

    If you haven't already, read through the docs on update()
    <https://www.firebase.com/docs/web/api/firebase/update.html>.

    If you still really don't think this will work for your use case, let me
    know and I can throw out some more suggestions.

    Jacob


    On Wed, Aug 6, 2014 at 9:34 AM, Matt Martin <matt...@gmail.com
    <javascript:>> wrote:
    Two sets of information: users and contacts.

    - The user can add contacts to the general contacts set, which is
    shared among all users.
    - The contacts set will eventually be quite, quite large.
    - The user uploads sets of contacts from an external source, so I get
    them all at once.
    - A new contact record will be created for every single phone number,
    which will be used as the key for the object. (e.g., 16125555555)

    So, here's the question: I'd ideally like to take the whole batch of new
    contacts, standardize the number formats, rip out the data I need, and
    create the objects in one pass client side and then send the whole set back
    to firebase. But the catch is that some of those contacts may already
    exist, so if I just do a simple "set", I'll overwrite the existing contact.
    I could cycle through each one and do a set at the specific key, but not
    only will that be costly, but I would have to go one level lower to ensure
    no data is overwritten (if they key is the same, I want to *add* data to
    the key, not overwrite existing properties). I could use update, but then I
    don't get the new ones. I could pull down the whole contact data set,
    iterate through it client side, and send it back all together but that's
    going to be slow both on the network (the data sets can be quite large) and
    client side (a lot of processing).

    Ideally, there would be some setOrUpdate function... but I don't think
    that exists.

    Thoughts?

    --
    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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/c47a96c7-0c0e-4b74-a534-661eca96ab87%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/c47a96c7-0c0e-4b74-a534-661eca96ab87%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/aa68ea35-b63a-46e4-92d2-3710b4d40dfe%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedAug 6, '14 at 6:00p
activeAug 6, '14 at 10:57p
posts3
users2

2 users in discussion

Matt Martin: 2 posts Jacob Wenger: 1 post

People

Translate

site design / logo © 2021 Grokbase