我的数据:
我有category,Sub category 1和sub category2。我通过使用parent_id存储每个类别。这是我的数据
{
"_id" : ObjectId("000000005e712c388852b550"),
"__v" : 0,
"category" : "ewb",
"created_date" : ISODate("2019-01-09T06:55:57.376Z"),
"parent_id" : null,
"status" : "Y",
"type" : "Column"
}
{
"_id" : ObjectId("000000005e712c388852b551"),
"__v" : 0,
"category" : "wealth",
"created_date" : ISODate("2019-01-09T06:55:57.378Z"),
"parent_id" : ObjectId("000000005e712c388852b550"),
"status" : "Y"
}
{
"_id" : ObjectId("000000005e712c388852b552"),
"__v" : 0,
"category" : "hh economic well-being",
"created_date" : ISODate("2019-01-09T06:55:57.379Z"),
"parent_id" : ObjectId("000000005e712c388852b551"),
"status" : "Y"
}
现在我必须打印为
Category : [{
category : 'ewb',
"_id" : ObjectId("000000005e712c388852b550"),
sub_cat1 : [{
category : 'wealth',
"_id" : ObjectId("000000005e712c388852b551"),
sub_cat2 : [{
category : 'hh economic well-being',
"_id" : ObjectId("000000005e712c388852b552"),
}]
}]
}]
在不更改架构的情况下如何实现此目的。我指的是