Backend -Code: < /p>
Code: Select all
def fetch_all_replies(id, comment_id):
data_to_return = []
post = posts.find_one(
)
for comment in post["comments"]:
comment["_id"] = str(comment["_id"])
for reply in comment["replies"]:
reply["_rid"] = str(reply["_rid"])
data_to_return.append(reply)
return make_response( jsonify( data_to_return), 200 )
< /code>
Datenbankstruktur: < /p>
[
{
"_id": "63f4cbb5462827492d6ee419",
"description": "Join us on a hike of cake hill to see the stunning sunrise!!",
"comments": [
{
"_id": "63f7ba0deca5ad33c3c18ed0",
"comment": "is this park dog friendly?",
"replies": [
{
"_rid": "63f7fe6e16423c052a18cf8c",
"comment": "Yeah, this park is dog friendly!",
"username": "Beth"
}
]
Code: Select all
[
{
"_id": "63f9ee3194ea5d46da5472c6",
"comment": "Do i need much experience to do this hike?",
"replies": [
{
"_rid": "63ff744d03b399e52def7d3d",
"comment": "Yes, i'm brining my spring spaniel ",
"username": "sarah"
}
],
"username": "Rachel"
}
]
Code: Select all
[
{
"_rid": "63f7fe6e16423c052a18cf8c",
"comment": "Yeah, this park is dog friendly!",
"username": "Beth"
},
{
"_rid": "63ff74de03b399e52def7d3e",
"comment": "This is my first hike",
"username": "Anna"
},
{
"_rid": "63ff752a03b399e52def7d3f",
"comment": "I've hiked up cave hill several times!",
"username": "Juno"
},
{
"_rid": "63ff744d03b399e52def7d3d",
"comment": "Yes, i'm brining my spring spaniel ",
"username": "sarah"
}
]