For example a tree structure as;
[
{id: 1 , childrenIdList: [2, 3]},
{id: 2 , childrenIdList: [4, 5]},
{id: 3 , childrenIdList: []},
{id: 4 , childrenIdList: [6, 7]},
{id: 5 , childrenIdList: []},
{id: 6 , childrenIdList: []},
{id: 7 , childrenIdList: []}
]
which is like;
1
2 3
4 5
6 7
How can I trace tree from starting the leaf node(id=7) to root(id=1)?
Finding the parent of id=7
is easy as;
db.document.find({childrenList: { $in: [7]}}, {id: 1}).toArray(function(err), result{
/*result gives
{"id" : NumberInt(4)}
now I should look the parent of id=4, and parent of id=2 as you know.
*/
})
Is recursive queries possible on mongodb? How can I implement it?