0

is it possible to queryOrdered 2 times with Firebase? I first want to put the post on top with the most points and then I want to filter their age just like I did. If I run this I get an "Thread 1: signal SIGABRT "Error. How can i fix this?

func observeAllAgePosts(completion: @escaping (Post) -> Void) {
            REF_POSTS.queryOrdered(byChild: "points").queryStarting(atValue: 0)
                .queryEnding(atValue: 100000).queryOrdered(byChild: "Age").queryStarting(atValue: Age11)
                .queryEnding(atValue: Age22).observeSingleEvent(of: .value, with: {
                    snapshot in
                    if snapshot.hasChildren(){
                    let arraySnapshot = (snapshot.children.allObjects as! [DataSnapshot]).reversed()
                    arraySnapshot.forEach({ (child) in
                        if let dict = child.value as? [String: Any] {
                            let post = Post.transformPostPhoto(dict: dict, key: child.key)
                            completion(post)
                        }
                    })
                    }else{
                        ProgressHUD.dismiss()
                    }
                })
        }

My structure:

enter image description here

Dani Kemper
  • 343
  • 2
  • 10
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Oct 01 '18 at 14:28
  • In your example, since both values seem numeric, I doubt it is possible to combine them into a single property. The best you can probably do is filter for age in a query, and then order them by points client-side. – Frank van Puffelen Oct 01 '18 at 14:29

0 Answers0