1

I would like to export multiple mongo collection to single JSON file.

For easy understanding, lets define the sample collections below

Collection 1: Order

{
    "_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
}

Collection 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"
    }
}

Collection 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"
    }
}

Collection 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"
}

My question as follows

  1. How to export the above 4 collections to single json as follows

    { "_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" } } ] }

Thanks in advance!

Tamil
  • 1,193
  • 9
  • 24

0 Answers0