0

I have a string that is equal to a list of other strings.

var postingID: String?

func loadDetails(){
    Database.database().reference().child("main").child("users").child(screenName!).child("bookmarks").observeSingleEvent(of: .value, with: { (snapshot:DataSnapshot) in

        if let postsDictionary = snapshot .value as? [String: AnyObject] {
             for testingkey in postsDictionary.keys {
                self.postingID = testingkey
             }
        }})  
}

PostingID can result in a number of strings. Is it possible to queryEqual = multiple strings?

func loadData(){
        Database.database().reference().child("main").child("posts").queryOrdered(byChild: "id").queryEqual(toValue: PostingID).observeSingleEvent(of: .value, with: { (snapshot) in

            for child in snapshot.children {
                let snap = child as! DataSnapshot
                let dict = snap.value as! [String: Any]

                self.posts.insert(dict, at: 0)
                self.Bookmark.reloadData()
            }

            print(snapshot)

        })
    }

I just want to be able to print out all the post that the postingID prints out. If the postingID prints outs more than one posts, I want to print all those posts out in my table view.

Jay
  • 34,438
  • 18
  • 52
  • 81
juelizabeth
  • 485
  • 1
  • 8
  • 31
  • Nope. Firebase Database queries can only compare a single property against a single value. It does not have an equivalent of `SELECT * FROM posts WHERE id IN (1,2,3)`. Performance-wise it doesn't need this, since retrieving the items separately has equivalent performance. See https://stackoverflow.com/questions/40910884/how-to-perfom-query-sql-in-clause-in-firebase-android – Frank van Puffelen Jul 14 '18 at 16:41
  • 1
    ...or.... store a reference to the user in each bookmark and perform a query on that reference which will then in turn just load those bookmarks. You may also want to consider not using a screenname as a node key as screennames can change and they will break references. Use .childByAutoId to create node keys and store those keys within each bookmark. – Jay Jul 17 '18 at 22:04

0 Answers0