我想将多个mongo集合导出为单个JSON文件。
为了便于理解,我们来定义下面的样本集
收藏1:订单
{
"_id": "01LS0PnHCR",
"title": "Test Title",
"when": {
"$date": "2018-01-31T00:00:00.000Z"
},
"_p_orderData": "OrderData$02OOnDuJnM", // Reference of OrderData collection -> 02OOnDuJnM
"_created_at": {
"$date": "2017-01-27T12:24:30.449Z"
},
"_updated_at": {
"$date": "2017-02-01T12:48:46.026Z"
},
"_p_user": "_User$hCiOOgQkOC" // Reference of _User collection -> hCiOOgQkOC
}
收集2: OrderData
{
"_id": "02OOnDuJnM",
"orderDescription": "Test Description",
"_created_at": {
"$date": "2017-01-11T21:23:01.132Z"
},
"_updated_at": {
"$date": "2017-01-11T21:23:01.132Z"
}
}
收集3: OrderComment
{
"_id": "04tNm4U7sm",
"_p_order": "Order$01LS0PnHCR", // Reference of Order collection -> 01LS0PnHCR
"type": "text",
"comment": "cute",
"_p_user": "_User$BKOIWDtzQ0", // Reference of _User collection -> BKOIWDtzQ0
"_created_at": {
"$date": "2017-01-06T13:47:14.478Z"
},
"_updated_at": {
"$date": "2017-01-06T13:47:14.478Z"
}
}
收藏4: _User
{
"_id": "hCiOOgQkOC",
"username": "testing",
"_created_at": {
"$date": "2017-01-11T07:52:14.157Z"
},
"_updated_at": {
"$date": "2017-02-09T22:13:16.904Z"
},
"firstName": "Tes",
"email": "testing@gmail.com",
"lastName": "Ing"
}
我的问题如下
如何将上述4个集合导出为单个json,如下所示
{
"_id": "01LS0PnHCR",
"title": "Test Title",
"when": {
"$date": "2018-01-31T00:00:00.000Z"
},
"_p_orderData": {
"_id": "02OOnDuJnM",
"orderDescription": "Test Description",
"_created_at": {
"$date": "2017-01-11T21:23:01.132Z"
},
"_updated_at": {
"$date": "2017-01-11T21:23:01.132Z"
}
},
"_created_at": {
"$date": "2017-01-27T12:24:30.449Z"
},
"_updated_at": {
"$date": "2017-02-01T12:48:46.026Z"
},
"_p_user": {
"_id": "hCiOOgQkOC",
"username": "testing",
"_created_at": {
"$date": "2017-01-11T07:52:14.157Z"
},
"_updated_at": {
"$date": "2017-02-09T22:13:16.904Z"
},
"firstName": "Tes",
"email": "testing@gmail.com",
"lastName": "Ing"
},
"OrderComment": [ // New attribute added to dream with array of comments
{
"_id": "04tNm4U7sm",
"_p_order": "Order$01LS0PnHCR",
"type": "text",
"comment": "cute",
"_p_user": "_User$BKOIWDtzQ0",
"_created_at": {
"$date": "2017-01-06T13:47:14.478Z"
},
"_updated_at": {
"$date": "2017-01-06T13:47:14.478Z"
}
}
]
}
提前致谢!