0

I have the following JSON, How to convert an array of objects with object ids to string in MongoDB using aggregation query?

{
"_id": ObjectId("60e41eb7335412757cc6cb9a"),
"items": [
    {
        "_id": ObjectId("60e4566a461e7a2cf9de14be"),
        "buyers": [
            ObjectId("60e4566a461e7a2cf9de14be"), 
            ObjectId("60e4566a461e7a2cf9de14be"), 
            ObjectId("60e4566a461e7a2cf9de14be")
        ],
        "sellers": [
            ObjectId("60e4566a461e7a2cf9de14be"),
            ObjectId("60e4566a461e7a2cf9de14be")
        ],
        "description": "tes product 5 Lorem ipsum dolor sit, consectetur",
        "owner": ObjectId("60d8c31af30fe429ffab1dc2"),
        "product": ObjectId("60d49fa36a232668ded042cf"),
        "createdAt": ISODate("2021-07-06T13:11:06.818Z"),
        "updatedAt": ISODate("2021-07-06T13:11:06.818Z"),
        "createdBy": {
            "_id": ObjectId("5eeaf3aead7cef7f1958f284"),
            "name": "John Doe",
            "createdAt": ISODate("2020-06-18T04:55:10.869Z"),
            "updatedAt": ISODate("2021-07-26T08:17:33.934Z"),
            "__v": 0,
            "isAdmin": true,
            "dkeys": [ 
                ObjectId("5f754b501b8d9c3e998727fd")
            ],
            "tries": [ 
                ObjectId("60e8524ab63c35635d84cce6")
            ]
        },
        "__v": 0
    },
    {
        "_id": ObjectId("60e4566a461e7a2cf9de14be"),
        "buyers": [ObjectId("60e4566a461e7a2cf9de14be"), ObjectId("60e4566a461e7a2cf9de14be"), ObjectId("60e4566a461e7a2cf9de14be")
        ],
        "sellers": [ObjectId("60e4566a461e7a2cf9de14be"),ObjectId("60e4566a461e7a2cf9de14be")
        ],
        "description": "tes product 5 Lorem ipsum dolor sit, consectetur",
        "owner": ObjectId("60d8c31af30fe429ffab1dc2"),
        "product": ObjectId("60d49fa36a232668ded042cf"),
        "createdAt": ISODate("2021-07-06T13:11:06.818Z"),
        "updatedAt": ISODate("2021-07-06T13:11:06.818Z"),
        "createdBy": {
            "_id": ObjectId("5eeaf3aead7cef7f1958f284"),
            "name": "John Doe",
            "createdAt": ISODate("2020-06-18T04:55:10.869Z"),
            "updatedAt": ISODate("2021-07-26T08:17:33.934Z"),
            "__v": 0,
            "isAdmin": true,
            "dkeys": [ 
                ObjectId("5f754b501b8d9c3e998727fd")
            ],
            "tries": [ 
                ObjectId("60e8524ab63c35635d84cce6")
            ]
        },
        "__v": 0
    },
],
"isActive": true,
"ranges": [ 
    ObjectId("5edf2a8dfdbe5ad362a0b0d9"), 
    ObjectId"5edf2a8dfdbe5ad362a0b0d9")
],
"buyers": [ObjectId("60e4566a461e7a2cf9de14be"), ObjectId("60e4566a461e7a2cf9de14be"), ObjectId("60e4566a461e7a2cf9de14be")
],
"sellers": [ObjectId("60e4566a461e7a2cf9de14be"),ObjectId("60e4566a461e7a2cf9de14be")
],
"description": "tes comment 3 Lorem ipsum dolor sit, consectetur",
"updatedBy": ObjectId("5eeaf3aead7cef7f1958f284"),
"author": {
    "_id": ObjectId("60d8c31af30fe429ffab1dc2"),
    "raids": [ 
        ObjectId("5edf2a8dfdbe5ad362a0b0d9")
    ],
    "isActive": true,
    "feedbacks": [ 
        ObjectId("60dd8dd8ff27c726140c825e"), 
        ObjectId("60dd931f68d36823c8df2bfc"), 
        ObjectId("60e3cda61b26fb21e83aaae8"), 
        ObjectId("60e4025b9118a25bc322b698"), 
        ObjectId("60e410354c0f6c1d3c9390a0"), 
        ObjectId("60e41e8a335412757cc6cb8f"), 
        ObjectId("60e41eb7335412757cc6cb9a"), 
        ObjectId("60e449c9568c155565db6356"), 
        ObjectId("60e44a836b18f555ad10b557"), 
        ObjectId("60e45348bce3bb3f90c94081"), 
        ObjectId("60e4547810f0233cf86010b1"), 
        ObjectId("60e45691461e7a2cf9de1785"), 
        ObjectId("60e4569a461e7a2cf9de178e")
    ],
    "description": "product bought",
    "type": "text",
    "updatedBy": ObjectId("5eeaf3aead7cef7f1958f284"),
    "createdBy": ObjectId("5eeaf3aead7cef7f1958f284"),
    "createdAt": ISODate("2021-06-27T18:27:38.609Z"),
    "updatedAt": ISODate("2021-07-22T13:27:47.677Z"),
    "__v": 0,
    "items_feedbacks": [
        {
            "_id": ObjectId("60e4348685b26f31e8fc53af"),
            "code": "003",
            "message": "test msg for bad image",
            "createdBy": ObjectId("5eeaf3aead7cef7f1958f284")
        },
        {
            "_id": ObjectId("60e4348b85b26f31e8fc53b1"),
            "code": "003",
            "message": "test msg for bad image",
            "createdBy": ObjectId("5eeaf3aead7cef7f1958f284")
        },
        {
            "_id": ObjectId("60e4348d85b26f31e8fc53b4"),
            "code": "003",
            "message": "test msg for bad image",
            "createdBy": ObjectId("5eeaf3aead7cef7f1958f284")
        },
        {
            "_id": ObjectId("60e434d1491c363a304baf29"),
            "code": "003",
            "message": "test msg for bad image",
            "createdBy": ObjectId("5eeaf3aead7cef7f1958f284")
        },
        {
            "_id": ObjectId("60e434f91eb3f62874892b97"),
            "code": "003",
            "message": "test msg for bad image",
            "createdBy": ObjectId("5eeaf3aead7cef7f1958f284")
        }
    ]
},
"product": {
    "_id": ObjectId("60d49fa36a232668ded042cf"),
    "p_items": [ 
        ObjectId("60d4a1246a232668ded042d1"), 
        ObjectId("60d4a1aa6a232668ded042d3"), 
        ObjectId("60d4a1fb6a232668ded042d5"), 
        ObjectId("60d711a238b57d30ba384c2a"), 
        ObjectId("60d963ff38b57d30ba384d6a"), 
        ObjectId("60d9890567e5746355e30785"), 
        ObjectId("60d9890b67e5746355e30789"), 
        ObjectId("60d9d159c3c0f732200f48af"), 
        ObjectId("60d9d1bec3c0f732200f48b1"), 
        ObjectId("60dab30a5fe325044c6f2828"), 
        ObjectId("60dab8675fe325044c6f2be1"), 
        ObjectId("60dabd985fe325044c6f2c25"), 
        ObjectId("60dabdbd5fe325044c6f2c29"), 
        ObjectId("60daca035fe325044c6f2d61"), 
        ObjectId("60daca0d5fe325044c6f2d65"), 
        ObjectId("60dacb7c5fe325044c6f2d6a"), 
        ObjectId("60dacc3b5fe325044c6f2d78"), 
        ObjectId("60dacfbb5fe325044c6f2d7f"), 
        ObjectId("60dad1395fe325044c6f2d86"), 
        ObjectId("60dad1995fe325044c6f2d90"), 
        ObjectId("60dad2b05fe325044c6f2db2"), 
        ObjectId("60dad50a5fe325044c6f2dc3"), 
        ObjectId("60dad55b5fe325044c6f2dc7"), 
        ObjectId("60dad5605fe325044c6f2dcb"), 
        ObjectId("60dad9325fe325044c6f2e90"), 
        ObjectId("60dae48b5fe325044c6f2f0a"), 
        ObjectId("60dae4b25fe325044c6f2f0c"), 
        ObjectId("60dae6655fe325044c6f2f10"), 
        ObjectId("60dae7bc0aa85a0bcdd1c2ab"), 
        ObjectId("60daeb3795c4020de8e4e1db"), 
        ObjectId("60daed005fe325044c6f2f1a"), 
        ObjectId("60daf1f35fe325044c6f3003"), 
        ObjectId("60daf2135fe325044c6f3007"), 
        ObjectId("60dafbcfa5790f56c638123c"), 
        ObjectId("60dafc64a5790f56c638123e"), 
        ObjectId("60dafcbea5790f56c6381240"), 
        ObjectId("60daff1fa5790f56c63812b3"), 
        ObjectId("60daffcb5aa2575ea6954e9e"), 
        ObjectId("60db01c00926b06046aa66de"), 
        ObjectId("60db01f50926b06046aa6756"), 
        ObjectId("60db2257609cc501b5f153ca"), 
        ObjectId("60db23f5609cc501b5f153cc"), 
        ObjectId("60db27d4de26e128bc6e430f"), 
        ObjectId("60db2fd8609cc501b5f15420"), 
        ObjectId("60db3276609cc501b5f15422"), 
        ObjectId("60db32a5609cc501b5f15424"), 
        ObjectId("60db32e1609cc501b5f15426"), 
        ObjectId("60db34da7e091a14da2869da"), 
        ObjectId("60db35017e091a14da2869df"), 
        ObjectId("60db35427e091a14da2869e4"), 
        ObjectId("60db35c87e091a14da2869ec"), 
        ObjectId("60db35ea7e091a14da286a84"), 
        ObjectId("60db3ae38810c91ad88b270d"), 
        ObjectId("60db3b4c8810c91ad88b270f"), 
        ObjectId("60db3b638810c91ad88b2711"), 
        ObjectId("60db3b848810c91ad88b2713"), 
        ObjectId("60db3cee8810c91ad88b2715"), 
        ObjectId("60db45758810c91ad88b2719"), 
        ObjectId("60db47798810c91ad88b271e"), 
        ObjectId("60db499d8810c91ad88b2725"), 
        ObjectId("60db4b828810c91ad88b272d"), 
        ObjectId("60db4bc08810c91ad88b2731"), 
        ObjectId("60db4c548810c91ad88b273f"), 
        ObjectId("60db50b08810c91ad88b2768"), 
        ObjectId("60dbef2b2927e20a5bd3ec5a"), 
        ObjectId("60dbef3d2927e20a5bd3ec60"), 
        ObjectId("60dbef452927e20a5bd3ec62"), 
        ObjectId("60dbf6042927e20a5bd3ec8c"), 
        ObjectId("60dbf6512927e20a5bd3ec8e"), 
        ObjectId("60dbfa1184dea73932b287a3"), 
        ObjectId("60dbfec12927e20a5bd3ece1"), 
        ObjectId("60dbfecd2927e20a5bd3ece7"), 
        ObjectId("60dbfed12927e20a5bd3ece9"), 
        ObjectId("60dbff912927e20a5bd3ecfd"), 
        ObjectId("60dc102d1e4d7b4a5296b06f"), 
        ObjectId("60dc51fa5564910f5c4bce1b"), 
        ObjectId("60dc67da5564910f5c4bfd8b"), 
        ObjectId("60dc684f5564910f5c4bfda7"), 
        ObjectId("60dc6fe75564910f5c4bfe09"), 
        ObjectId("60deb9b2dd5a28183c0e09be"), 
        ObjectId("60debc1edeae6f08944c3f1a"), 
        ObjectId("60def6af5233ef1fd00ee27d"), 
        ObjectId("60defa8fcae30f20dc0de723"), 
        ObjectId("60defac2cae30f20dc0de725"), 
        ObjectId("60defec720c27e57968ad568"), 
        ObjectId("60e2b223f2fa9a3b501a9d7b"), 
        ObjectId("60e2bb9e2dda722f40fe3580"), 
        ObjectId("60e2bc1442f57f24c4b04b88"), 
        ObjectId("60e2bc6cfbb27e3e6cba77bc"), 
        ObjectId("60e2c10bfbb27e3e6cba77c6"), 
        ObjectId("60e44aa66b18f555ad10b55f"), 
        ObjectId("60e44ad9cc482755d5814d7d"), 
        ObjectId("60f687bcc414a59d5a78d084"), 
        ObjectId("60f6895ff18f489dd8050325"), 
        ObjectId("60f68b20fd344e9e4aadb47a"), 
        ObjectId("60fe6f9d89a99c32484061dd")
    ],
    "updatedBy": ObjectId("5eeaf3aead7cef7f1958f284"),
    "createdAt": ISODate("2021-06-24T15:07:15.977Z"),
    "updatedAt": ISODate("2021-07-26T08:17:33.500Z"),
    "createdBy": ObjectId("5eeaf3aead7cef7f1958f284"),
    "__v": 0
}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.