Get record length without downloading the whole record.

158 views
Skip to first unread message

Federico Vázquez

unread,
Sep 30, 2015, 6:56:23 AM9/30/15
to Firebase Google Group
Actually, if I want to display how many `/users` I have on my app, I should first download the whole list of users and then `Array.length`, that's not so fancy...

Is there a way to simply retrieve how many records are in `/users` endpoint for example? 
And if now, can some dev suggest this feature to firebase team??

Dennis Smolek

unread,
Sep 30, 2015, 9:35:55 AM9/30/15
to Firebase Google Group
What we do is add a field called user_count so its /users/user_count

Then when we add/delete users we change that number

-D

Kato Richardson

unread,
Sep 30, 2015, 1:37:19 PM9/30/15
to Firebase Google Group
See http://stackoverflow.com/questions/15148803/in-firebase-is-there-a-way-to-get-the-number-of-children-of-a-node-without-load

Also, check out shallow=true from the REST API. I used that in Paginate to count the number of records without downloading all the data. Note that this does require loading all data into memory on the server, so if there are tens of GBs of data at the path, it may not be performant.

Both are solid approaches.



--
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/dd71cc6c-e95b-4a0e-a925-554f728cae57%40googlegroups.com.

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

Federico Vázquez

unread,
Sep 30, 2015, 6:27:28 PM9/30/15
to Firebase Google Group
So 2 years ago, this issue was noticed to firebase devs, Andrew Lee said that they plan to add it but still nothing? Basically the only way to do this without downloading all data is to maintain a counter "manually"?

Dennis Smolek

unread,
Sep 30, 2015, 6:34:45 PM9/30/15
to Firebase Google Group
Probably because with transactions and flattening the data the majority of dev's got around not being able to do a count() without it being too much of a pain.

Deep queries and atomic updates where much much much better priorities in my opinion. It's actually not too bad, there is the security issue of being able to inflate the counts but it's pretty edge case.

I was annoyed with it too but so far it's not really been a big deal. 

-D

Kato Richardson

unread,
Sep 30, 2015, 7:10:27 PM9/30/15
to Firebase Google Group

 Basically the only way to do this without downloading all data is to maintain a counter "manually"?

I presented two options: Using shallow=true, and using a counter. Neither downloads all the data. 

Counting the number of records hasn't proved to be a big demand. It will likely make it into the API, but not before big features like triggers and file uploads.

Hang in there!

☼, 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.

Federico Vázquez

unread,
Sep 30, 2015, 7:26:19 PM9/30/15
to Firebase Google Group
I appreciate your replies guys, although I don't quite understand what "Deep queries and atomic updates" simply because I'm not an advanced developer yet :)
About the examples using shallow=true, I'm not able to make use of a node server, that's why it's not viable in my case.. I can't load all data into any memory because of no server, just a simple SPA


El miércoles, 30 de septiembre de 2015, 7:56:23 (UTC-3), Federico Vázquez escribió:

Kato Richardson

unread,
Sep 30, 2015, 7:31:01 PM9/30/15
to Firebase Google Group
Federico,

The good news is that REST requests can be made from your browser and do not require a server process. The link I shared is also to a client-side library.

If you're using jQuery, Angular, or most any framework, they have such things built in ($.ajax() and $http.get() respectively). If not, the example I pointed to utilizes microAjax, a handy little HTTP lib.

☼, 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.

Federico Vázquez

unread,
Sep 30, 2015, 7:38:20 PM9/30/15
to Firebase Google Group
I'm using angularfire generator, so if I install Firebase.utils shall I be able to count the number of entries in `/users` endpoint without downloading the whole record? Where is going all the data you talk about when "loading all data into memory" then?
Reply all
Reply to author
Forward
0 new messages