How to get Firebase nodes names without getting their children too in Firebase response?

3,909 views
Skip to first unread message

Ashraf Bashir

unread,
Jun 20, 2013, 7:18:53 AM6/20/13
to fireba...@googlegroups.com

 

I have the following hierarchy on firebase, some data are hidden for confidentiality:

enter image description here

I'm trying to get a list of videos IDs (underlines in red)

I only can get all nodes, then detect their names and store them in an array!
But this causes low performance; because the dataSnapshot from firebase is very big in my case, so I want to avoid retrieving all the nodes' content then loop over them to get IDs, I need to just retrieve the IDs only, i.e. without their nested elements.

Here's my code:

new Firebase("https://PRIVATE_NAME.firebaseio.com/videos/").once(
    'value', 
    function(dataSnapshot){ 

        // dataSnapshot now contains all the videos ids, lines & links
        // this causes many performance issues

        // Then I need to loop over all elements to extract ids !
        var videoIdIndex = 0;
        var videoIds = new Array();

        dataSnapshot.forEach(
            function(childSnapshot) {
                videoIds[videoIdIndex++] = childSnapshot.name();
            }
        );

    }
);

How may I retrieve only IDs to avoid lot of data transfer and to avoid looping over retrived data to get IDs ? is there a way to just retrive these IDs directly ?

Donovan

unread,
Jun 20, 2013, 12:52:18 PM6/20/13
to fireba...@googlegroups.com
Have you considered storing the IDs in a separate place as well?  You'll have to double up on writes to save yourself on reads, but that tends to be the mantra of nosql.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michael "Kato" Wulf

unread,
Jun 20, 2013, 12:56:52 PM6/20/13
to fireba...@googlegroups.com
Ashraf,

Check out your stack overflow question. I've answered this earlier this morning.

The short answer is no, you cannot retrieve keys without fetching the underlying data. Long answer is that you need to denormalize to fix your performance.
--
Michael Wulf
www.wordspot.org


Lewis Cowles

unread,
Jun 21, 2013, 2:28:57 PM6/21/13
to fireba...@googlegroups.com
Also consider using not one thing, but the right tool for each job, so per-user settings are really what a nosql store is great for, as are threads etc, it is remarkably fast, but storing say a geo-search co-ordinates is not really the smartest thing to be doing and could be heavily optimized by adopting a hybrid approach. Also remember that the duplication advice will force up your storage costs as well as bandwidth costs (so it wou

Michael Lehenbauer

unread,
Jun 21, 2013, 3:02:34 PM6/21/13
to fireba...@googlegroups.com
FYI- As others explained, denormalization is the solution for now, but we do see getting only child names as an important use case and we'll be adding support for this in the future.

-Michael
Reply all
Reply to author
Forward
0 new messages