0

I have some 'posts' in my ios App running with swift 3 and firebase.

Right now i'm calling only pose with a true value for the condition 'pubished' with the following:

readPosts = Post.observeList(from: Post.parentReference.queryOrdered(byChild: "published").queryEqual(toValue: true))

    {



        observedPosts in

        posts = observedPosts.reversed()
        self.feedTableView.reloadData()
    }

I would like instead to call post only with the condition 'published' and a value 'true', to call post with the conditions 'published' ( value 'true' AND 'privacy' with another value 'false')

how is this doable ? I'm turning crazy with it, thanks a lot :) :)

--- EDIT

The structure of my DB is the following:

    {
  "posts" : {

"KbzQAkcMZgT524RAIPj" : {
  "caption" : "caption text",
  "created" : 1486049033502,
  "creator" : "A25Aw84Li0NygXRMrCzerOSxgNY2",
  "imageUrl" : "https://firebasestorage.googleapis.com/v0/b/myserver-0.appspot.com/o/a--bl.jpg?alt=media&token=7-",
  "link" : "https://s3.amazonaws.com/ray.wenderlich/elephant_safari.mp4",
  "privacy" : "no",
  "published" : true,
  "title" : "COMING SOON"
},
"KbzQAkcMZgT524RAIPk" : {
  "caption" : "caption text",
  "created" : 1486049033402,
  "creator" : "o9epRntmZaNe2LdTUJV2g1zr54C2",
  "imageDetails" : "https://firebasestorage.googleapis.com/v0/b/myserver.appspot.com/o/a--bl.jpg?alt=media&token=6-",
  "imageUrl" : "gs://myserver.appspot.com/boa-bl.jpg",
  "link" : "https://s3.amazonaws.com/ray.wenderlich/elephant_safari.mp4",
  "privacy" : true,
  "published" : false,
  "title" : "COMING SOON"
}
  }
}
tibewww
  • 593
  • 4
  • 11
  • 32
  • 2
    Firebase Database queries can only order/filter on a single property. This has been covered *many* times before. For this specific scenario, I recommend having a look at http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase and http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value. – Frank van Puffelen Feb 16 '17 at 17:53
  • Hi Frank, Thanks for those, I've been reading those but it doesn't seem to be for Swift/ iOS, so i get a bit lost and confuse, do you know about iOS how can we achieve it ? – tibewww Feb 16 '17 at 18:12
  • The approach is the same across all platforms. In fact: one of my answers has no code for any platform and purely shows a data model. – Frank van Puffelen Feb 16 '17 at 18:56
  • Thanks Frank, Im digging into it, I ve edit my questions with a screenshot of my Db structure, which is flat, can it work like that ? as it sees the parents and child of your example are different – tibewww Feb 16 '17 at 19:09
  • 1
    Please replace that screenshot with the actual JSON as text, which you can easily get by clicking the Export JSON link in [your Firebase Database console](https://console.firebase.google.com/project/_/database/data/). Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Feb 16 '17 at 19:21
  • Aside from that: a flat data structure SQL, but you're working on a NoSQL database. You also haven't added any composite property yet, combining the values that you want to query on. – Frank van Puffelen Feb 16 '17 at 19:22
  • Hi Frank, I've updated it – tibewww Feb 16 '17 at 19:25

0 Answers0