Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Recursive function - to get Children(might be parents too) of parents
output sample
|-- Child 1.1
|-- Child 1.1.1
|-- Child 1.1.2
|-- Child 1.1.2.1
|-- Child 1.1.3
|-- Child 1.1.3.1
|-- Child 1.2
Parent 2
|-- Child 2.1
|-- Child 2.1.1
|-- Child 2.1.2
|-- Child 2.1.2.1
|-- Child 2.1.3
|-- Child 2.1.3.1
|-- Child 2.1.3.1.1
|-- Child 2.2
|-- Child 2.3

db sample
/* 0 */
{
"_id" : "22",

"path" : "null",
"created" : ISODate("2014-08-22T06:40:55.790Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "hh jj kk mm",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 1 */
{
"_id" : "23",

"path" : "22",
"created" : ISODate("2014-08-22T06:43:17.072Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "jjj",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 2 */
{
"_id" : "24",

"path" : "null",
"created" : ISODate("2014-08-22T06:57:33.185Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "jjjjj",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 3 */
{
"_id" : "25",
"
"path" : "null",
"created" : ISODate("2014-08-22T07:00:27.978Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "jjjjj",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 4 */
{
"_id" : "26",

"path" : "24",
"created" : ISODate("2014-08-22T07:05:16.697Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "kkkk",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 5 */
{
"_id" : "27",

"path" : "25",
"created" : ISODate("2014-08-22T07:07:46.522Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "hherr tthe",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 6 */
{
"_id" : "28",

"path" : "null",
"created" : ISODate("2014-08-26T05:11:19.146Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "kkk",
"thread_id" : "1009",
"thread_type" : "PHOTO"
}

/* 7 */
{
"_id" : "29",

"path" : "28",
"created" : ISODate("2014-08-22T06:43:23.072Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "jjjjjjjjj",
"thread_id" : "1001",
"thread_type" : "PHOTO"
}

/* 8 */
{
"_id" : "30",

"path" : "null",
"created" : ISODate("2014-07-23T06:40:55.790Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "hh jj kk mm",
"thread_id" : "1002",
"thread_type" : "PHOTO"
}

/* 9 */
{
"_id" : "31",

"path" : "null",
"created" : ISODate("2014-07-21T06:40:55.790Z"),
"user_name" : "rajesh",
"user_id" : "H001",
"body" : "hh jj kk mm",
"thread_id" : "1009",
"thread_type" : "PHOTO"
}
Posted
Comments
Richard MacCutchan 23-Aug-14 3:26am    
Is there a question somewhere in there?
basker A 23-Aug-14 3:32am    
yes
Richard MacCutchan 23-Aug-14 3:58am    
As pointless responses go that would be difficult to beat.
basker A 23-Aug-14 4:48am    
how to achieve path :null values are main parents
path :_id values are to get Children(might be parents too) of parent path null and contain _id of child row

id:1
path:null

id:1.1 //parent of 1.1.1//child of 1
path:1

id:1.1.1 //parent of 1.1.1.1 //child of 1.1
path:1.1

id:1.1.1.1 //child of 1.1.1
path:1.1.1

id:1.2//child of 1
path:1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900