"how to make firebase database query to get some of the children using swift 3?" Code Answer

5

as el capitain said, you'll need to use this:

func loaddata(){

    let ref = firdatabase.database().reference().child("posts")

    ref?.queryordered(bychild: "des").queryequal(tovalue: "11").observe(.childadded, with: { snapshot in 
        if let post = snapshot.value as? [string : anyobject] { 
            // do stuff with 'post' here.

        } 
    })

}

also, as he mentioned, you'll want to set your security rules to allow you to search by 'des', or whatever other child node you'll be querying by. in addition, you'll need to set the rules to allow you read access to the query location:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",

    "posts": {
      "$someid": {
        ".indexon": ["des"]
      }
    }
  }
}

however, you're not going to get 'only the images' though, your query will return the entire node. in this case, the query above would return the rrrrrr node.

By Paul Humphreys on May 10 2022

Answers related to “how to make firebase database query to get some of the children using swift 3?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.