0

Does it have solution? When I read in firebase documentation, it said "You can only use one order-by method at a time. Calling an order-by method multiple times in the same query throws an error."

let recentPostsQuery = (ref?.child("posts").queryOrdered(byChild: "postType").queryEqual(toValue: "1").queryOrdered(byChild: "timestamp"))

I wrote like that. But I found some problem. Does it have any solution? Thank.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • You need to use queryEqual first and then queryOrdered and it has to be called one time. So the solution would be `ref?.child("posts").queryEqual(toValue: "1").queryOrdered(byChild: "postType")` and then use `sort` method after you get the data to sort the "timestamp" – Jad Jan 07 '17 at 11:45
  • 1
    You can't do that, as specified in the documentation. The queryOrdered:byChild defines the ordering of the data, and the data can only be ordered by one parameter. However, if we knew your Firebase Structure (as text please, no images) there may be a solution. – Jay Jan 07 '17 at 13:29
  • Can you please be more specific about the problem you found and the query you want to perform? Is it posts ordered by timestamp whose postType value equal to 1? – Mochi Jan 07 '17 at 15:04
  • See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jan 07 '17 at 16:26
  • If i will write like below the code, will it cause performance problem when the data was big? `let recentPostsQuery = (ref?.child("posts").queryOrdered(byChild: "postType").queryEqual(toValue: "1") recentPostsQuery?.observe(FIRDataEventType.value, with: { (snapshot) in var arrayList = snapshot.value as! NSDictionary if arrayList.postType == "1" { //show the list } })` – Thant Han Lin Jan 08 '17 at 01:58

0 Answers0