1

I want to filter data from firebase, Im using firebase-util scroll for scrolling,

I have the following code

var baseRef = new Firebase(urlToFirebaseData).orderByChild("name").equalTo("john_doe");
var scrollRef = new Firebase.util.Scroll(baseRef, '$priority');

// establish an event listener as you would for any Firebase ref
scrollRef.on('child_added', function(record) {
    console.log('added child', record);
});

this gives me an error

Error: First argument to Firebase.util.Scroll must be a valid Firebase ref. It cannot be a Query (e.g. you have called orderByChild()).require.18.r.Scroll

how can I query using firebase-util, I have tried putting the query in different places to no avail

David
  • 1,139
  • 3
  • 10
  • 16

1 Answers1

1

The error message is pretty explicit:

First argument to Firebase.util.Scroll must be a valid Firebase ref. It cannot be a Query

The reason for this is that Firebase.util.scroll needs to build its own query to be able to implement scrolling on that location and Firebase only handles one query per location.

If you want to use Firebase.util.Scroll for the scrolling, you'll have to separate the data out into its own location so that you can do something like:

var baseRef = new Firebase(urlToFirebaseData).child("users_items").child("john_doe");
var scrollRef = new Firebase.util.Scroll(baseRef, '$priority');
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • the problem with that is the data is structured in such a way as the first child has random keys and I have no control in setting it. Basically it looks like this {{-lskdsdfsf: {'name':"john_doe"}},{-tedsf: {'name':"jane_doe"},{etc...}}. I dont want to download the whole data to the client first, as 1 node has a lot of data – David Aug 31 '15 at 06:13
  • You'll need to restructure the data to make this work, David. Good data structure is key in scalable NoSQL data stores. – Kato Sep 01 '15 at 18:24
  • @Kato The data is almost flat, but I have no control how the data is stored in firebase, it is being set by another app which I have no control over, Is there another way of doing this? – David Sep 01 '15 at 21:13