I would suggest an alternative
users
uid_0
name: "Frank"
uid_1
name: "Biff"
posts
post_0
msg: "some post"
user_id: "uid_0"
post_1
msg: "Another post"
user_id: "uid_1"
then a simple query will return all of uid_0's posts
let postsRef = root.child("posts")
postsRef.queryOrdered(byChild: "user_id").queryEqual(toValue: "uid_0")
.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot) //prints all of uid_0's posts
})
This avoids the need to gather up the post id's and then try to perform a SQL-like query WHERE Posts.ID in (k1, k2, k3...) as Firebase doesn't offer a query like that directly.
In response to a follow up comment about how to handle when a single post has multiple users...
posts
post_0
msg: "some post"
users:
uid_0: true
uid_1: true
post_1
msg: "Another post"
users:
uid_1: true
uid_2: true
The code to get the nodes that contain uid_1: true is similar and called a deep query or deep paths. That's an older post but will give you really good information.
let postsRef = root.child("posts")
postsRef.queryOrdered(byChild: "users/uid_1").queryEqual(toValue: true)
.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot) //prints all of uid_0's posts
})