目前我们的收集结构如下所示
db.testcol.insert({"name":"root_node","ip":"10.10","addr":"123 Node12"});
db.testcol.insert({"name":"first_level_1","ip":"10.10","addr":"123 Node12","parent_name":"root_node"});
db.testcol.insert({"name":"second_level","ip":"10.10","addr":"123 Node12","parent_name":"first_level_1"});
db.testcol.insert({"name":"first_level_2","ip":"10.11","addr":"13 Node123","parent_name":"root_node"});
db.testcol.insert({"name":"second_level_1","ip":"10.11","addr":"13 Node123","parent_name":"first_level_2"});
db.testcol.insert({"name":"third_level_l","ip":"10.11","addr":"13 Node123","parent_name":"second_level_1"});
db.testcol.insert({"name":"third_level_2","ip":"10.11","addr":"13 Node123","parent_name":"second_level_1"});
现在我将从前端传递根节点,我将显示level1,level2 ... level n文档。请告诉我怎么做。
在这个示例文档中,我将使用“root_node”进行搜索。它应该显示我要显示first_level,second_level和third_level文档。 Parent_name是关系键。
Edit: Expected Output: Input is "root_node"
-- First level children for "root_node"
/* 0 */
{
"_id" : ObjectId("56654b5b1160f16ccd252685"),
"name" : "first_level_1",
"ip" : "10.10",
"addr" : "123 Node12",
"parent_name" : "root_node"
}
/* 1 */
{
"_id" : ObjectId("56654b5b1160f16ccd252687"),
"name" : "first_level_2",
"ip" : "10.11",
"addr" : "13 Node123",
"parent_name" : "root_node"
}
-- Second level documents -- parent is second_level1 and second_leve2
/* 0 */
{
"_id" : ObjectId("56654b5b1160f16ccd252686"),
"name" : "second_level",
"ip" : "10.10",
"addr" : "123 Node12",
"parent_name" : "first_level_1"
}
/* 0 */
{
"_id" : ObjectId("56654b5b1160f16ccd252688"),
"name" : "second_level_1",
"ip" : "10.11",
"addr" : "13 Node123",
"parent_name" : "first_level_2"
}
/* 0 */
{
"_id" : ObjectId("56654b5b1160f16ccd252689"),
"name" : "third_level_l",
"ip" : "10.11",
"addr" : "13 Node123",
"parent_name" : "second_level_1"
}
/* 1 */
{
"_id" : ObjectId("56654b5b1160f16ccd25268a"),
"name" : "third_level_2",
"ip" : "10.11",
"addr" : "13 Node123",
"parent_name" : "second_level_1"
}