Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,863 members, 7,817,557 topics. Date: Saturday, 04 May 2024 at 02:19 PM

Threaded/nested Comment System Using Mongodb - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Threaded/nested Comment System Using Mongodb (2553 Views)

Discussion: What Is Your Opinion Of Mongodb / Yew Framework: Build Multi-threaded And Performant Web Front-end In Rust / Mongodb, React, Express, Node (mern) Developer Available Here! (2) (3) (4)

(1) (Reply) (Go Down)

Threaded/nested Comment System Using Mongodb by peterincredible: 12:22pm On Nov 06, 2019
hi fellow programmers i am working on a blog using reactjs and nodejs as the server and using mongoose (mongodb) as the database but am having a serious challenge am stuck at the creating the comment system i dont want to create this normal comment system just like the one nairaland is using i want to make it a nested/threaded comment system in which it will look like a tree or hirarchy in which the parent comment will be on top and the child comment will be under the parent and it will go down the three like that but the problem now is that i have researched for it on stackoverflow and mongodb website but it is just not clicking into my head and i am just confuse on how to go about it the problem am facing is
1. how to insert/reply a comment of a comment in the database and store it under the parent comment accordingly
2. how to get the comments both the nested ones
3. how to display it on the front end after getting all comments and the nested ones

pls am really confuse if any programmer here have faced this challenge using mongoose(mongodb) i will need your help or pls just point me to the right direction or link thanks
Re: Threaded/nested Comment System Using Mongodb by Nobody: 1:01pm On Nov 06, 2019
Im also stucked with this on Django. Any help?
Re: Threaded/nested Comment System Using Mongodb by peterincredible: 3:40pm On Nov 06, 2019
IamTeen:
Im also stucked with this on Django. Any help?
hmmm not sure sha but i think i have seen some little tutorial about it in youtube using django and doing the threaded/nested commenting system maybe you need to go check it out but as for nodejs i havent seen any relevant tutorial about that
Re: Threaded/nested Comment System Using Mongodb by ogunsinamayowa(m): 4:37pm On Nov 06, 2019
peterincredible:
hi fellow programmers i am working on a blog using reactjs and nodejs as the server and using mongoose (mongodb) as the database but am having a serious challenge am stuck at the creating the comment system i dont want to create this normal comment system just like the one nairaland is using i want to make it a nested/threaded comment system in which it will look like a tree or hirarchy in which the parent comment will be on top and the child comment will be under the parent and it will go down the three like that but the problem now is that i have researched for it on stackoverflow and mongodb website but it is just not clicking into my head and i am just confuse on how to go about it the problem am facing is
1. how to insert/reply a comment of a comment in the database and store it under the parent comment accordingly
2. how to get the comments both the nested ones
3. how to display it on the front end after getting all comments and the nested ones

pls am really confuse if any programmer here have faced this challenge using mongoose(mongodb) i will need your help or pls just point me to the right direction or link thanks


Hey! The logic is similar. To implement nested comments, you need to structure your database in such manner. I have a limited experience with NOSQL database, but you need to structure the document to make nested comments' json response for your front-end consumption. Then loop the nested json on jsx elements.
Re: Threaded/nested Comment System Using Mongodb by Kubernetes: 10:24pm On Nov 06, 2019
Re: Threaded/nested Comment System Using Mongodb by peterincredible: 8:51am On Nov 16, 2019
ogunsinamayowa:



Hey! The logic is similar. To implement nested comments, you need to structure your database in such manner. I have a limited experience with NOSQL database, but you need to structure the document to make nested comments' json response for your front-end consumption. Then loop the nested json on jsx elements.
yep thanks boss i have to do some stackoverflowing and it finally did it thanks for your reply it helped me alot
Re: Threaded/nested Comment System Using Mongodb by peterincredible: 9:08am On Nov 16, 2019
all right thank you all for your contributions and responses my able programmers and for those who is facing this problem or who will later come across it in feature this is the solution:
most database returns a flat array eg([1,2,3,4,5,6]) when you query it looking for a set of data irrespective of the database u are using eg(mongodb,mysql,mssql)so now for you to display it on the webpage base on their parent, child structure(some call it tree or nested structure) you have to find a way to convert it to a nested array eg[{name:"peter",parent:"segun" children:[...]},{name:"shabba",parent:"null",children[...]},{name:"alex",parent:null},...]
so that the parent will be at the top and the the children will be a another array in the object called children so when you finally convert it from flat to nested array you can then use a recursive function to display it on the htm as for me using reactjs i used a "recursive component" that is a component that calls itself to display it on the view so in summery for you to be able to solve this problem their are to major challange you have to face
1.converting flat array to nested array
2.displaying it on the front page using recursion function or recursive component and you are done

i hope i have save someone the headach i passed through anyway thanks once again and if you still need to c some code about it google it on stackoverflow you will see some code about it straight up bye

(1) (Reply)

Android Developers Group / Javac Welcome1.java Could Not Compile The Application I Wrote,please Help. / A Job Available For A Web Developer

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.