Firebase Filters and Pagination

I am trying to make a list of searchable messages stored in firebase, so I have firebse db like this

{
"post": {
    "postId": {
        "title": "bla bla bla",
        "date": "1/1/2015"
    },
    "postId2": {
        "title": "bla bla bla",
        "date": "2/1/2015"
    }
}}

Now I want to filter by name, just publish that their name begins with "bla bla", and then pager and sort by date, so I made this code:

 var posts=new Firebase(URL + "/post");
 posts=posts.orderByChild("title").startAt("bla bla").endAt("bla bla"+"z");//this will only show posts that starts with bla bla
 posts=posts.orderByChild("date").startAt(10).limitToFirst(10);//this will filter and show only the second page
 posts.on("value", function (raw_data) {
      //showing the results and more
 });

each of the requests works, but when I add them, I get an error message

Query.orderByChild: you cannot combine multiple orderBy calls.

How can i do this? I prefer not to use my own server and copy data to my server and do it there

+4
source share
1 answer

There are several ways to do this, but here is one way.

. :

var posts=new Firebase(URL + "/post");
posts=posts.orderByChild("title").startAt("bla bla").endAt("bla bla"+"z");
posts.on("value", function (raw_data) {
     //now craft a date query using the results from the posts query
     //  or, it could be filtered in code
});
0

All Articles