0

我在数据库中有如下记录(http://www.jsoneditoronline.org/?id=cb05d8495014d3581acaf3fa466d5e4c

          [{
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "_id" : ObjectId("XXX"),
            "controlprops" : {
                "height" : "200px",
                "width" : "300px",
                "position" : "absolute",
                "X" : "387px",
                "Y" : "228px",
                "sequenceId" : 1,
                "ParentId" : null,
                "Id" : "hKNBdf0"
            }
        }, 
        {
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "_id" : ObjectId("XXX"),
            "controlprops" : {
                "height" : "110px",
                "width" : "244px",
                "position" : "absolute",
                "X" : "16px",
                "Y" : "40px",
                "sequenceId" : 1,
                "ParentId" : "hKNBdf0",
                "Id" : "8aqaU39"
            }
        }, 
        {
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "_id" : ObjectId("XXX"),
            "controlprops" : {
                "height" : "110px",
                "width" : "244px",
                "position" : "absolute",
                "X" : "16px",
                "Y" : "40px",
                "sequenceId" : 1,
                "ParentId" : "hKNBdf0",
                "Id" : "8aqaU39"
            }
        }, 
        {
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "_id" : ObjectId("571868926383b14c1a1fbb1c"),
            "controlprops" : {
                "height" : "38px",
                "width" : "100px",
                "position" : "absolute",
                "X" : "48px",
                "Y" : "37px",
                "background_color" : "green",
                "color" : "rgb(255, 255, 255)",
                "sequenceId" : 2,
                "ParentId" : null,
                "Id" : "eSJfjXp"
            }
        }]

这里基于“controlprops”中的“ParentId”,“Id”,我想要具有父子关系的对象。

这里的输出会像(http://www.jsoneditoronline.org/?id=cb05d8495014d3581acaf3fa4617ea52):

 [{
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "controlprops" : {
                "height" : "200px",
                "width" : "300px",
                "position" : "absolute",
                "X" : "387px",
                "Y" : "228px",
                "sequenceId" : 1,
                "ParentId" : null,
                "Id" : "hKNBdf0"
            },
            "child" : [
              {
             "X" : "ValueofX",
             "Y" : "ValueofY",
            "controlprops" : {
                "height" : "110px",
                "width" : "244px",
                "position" : "absolute",
                "X" : "16px",
                "Y" : "40px",
                "sequenceId" : 1,
                "ParentId" : "hKNBdf0",
                "Id" : "8aqaU39"
             }
            },{
             "X" : "ValueofX",
             "Y" : "ValueofY",
            "controlprops" : {
                "height" : "110px",
                "width" : "244px",
                "position" : "absolute",
                "X" : "16px",
                "Y" : "40px",
                "sequenceId" : 1,
                "ParentId" : "hKNBdf0",
                "Id" : "8aqaU39"
             }
            }
            ]
        }
        , 
        {
            "X" : "ValueofX",
            "Y" : "ValueofY",
            "controlprops" : {
                "height" : "38px",
                "width" : "100px",
                "position" : "absolute",
                "X" : "48px",
                "Y" : "37px",
                "background_color" : "green",
                "color" : "rgb(255, 255, 255)",
                "sequenceId" : 2,
                "ParentId" : null,
                "Id" : "eSJfjXp"
            }
        }]

如何使用 mongodb/mongoose 实现它?任何帮助将不胜感激。

4

0 回答 0