我是mongodb的新手,我想存储一个树形结构。我阅读了有关它的官方mongodb教程(here),但我需要能够一次检索所有子树。因此,我将树映射到递归嵌入式对象中。
对于实例,假设每个节点都有自己的children
和content
。在我的设置中,children
映射到一个字段, {
_id:1,
content: "...",
children: [
{
_id:2,
content: "...",
children: [
{
_id:3,
content: "...",
children: [ ... ]
},
...
]
}, ...
]
}
映射到一个嵌入式文档数组,如下所示:
coon.Open();
var trans = coon.BeginTransaction();
var query = "DELETE FROM users_login WHERE UserID = @UserID;";
MySqlCommand cmd = new MySqlCommand(query, coon, trans);
cmd.Parameters.Add("@UserID", MySqlDbType.Int16).Value = oUsuario.UserID;
cmd.ExecuteNonQuery();
trans.Commit();
coon.Close();
1。基本上,我以正确的方式做到了吗?没有更好的溶剂吗?
2。如果我是正确的,我应该如何在“每个级别”上查找一个节点及其子树?
任何帮助将不胜感激。