I highly recommend first reading my classic answer on a similar question: Firebase data structure and url
Nesting data is in general discouraged in the Firebase Database. There have various reasons for that, but a few:
you can only retrieve a complete node. So if you nest the comments under each post, it means you will automatically get all comments whenever you are getting a post.
you often want different access rules on each of these types (posts vs comments). This is more difficult to manage when you nest them, since permission trickles down.
I would have three top-level lists: posts
and comments
.
posts
$postid
author: "uidOfCoderCody"
title: "Firebase Data Retrieval, Path Inside Path"
body: "I would like to know if it possible to..."
comments
$postid
$commentid
author: "uidOfZassX"
comment: "Here is sample code of how it should work."
Since the comments are stored under the same $postid
of the post itself, you can easily look up the comments for a post.
Depending on the use-cases that your app covers, you'll need to adapt or (more likely) expand this data model to efficiently allow your use-cases. For learning more, I also recommend reading this article on NoSQL data modeling.