'How to get fields of a different type when populate is not a ref ObjectId?

There is a mongodb collection called orders

[
    {
     _id: ObjectId('626101f10709bfd705ebaaff'),
     firstName: 'Peter',
     lastName: 'Parker',
     source: ObjectId('625fa062cc69b9ccda60ff4b')
    },
    {
     _id: ObjectId('6229b108fb9da9e4ee29dcc4'),
     firstName: 'Oliver',
     lastName: 'Williams',
     source: 'Instagram'
    },
    ...
]

When I make a populate request for a collection of orders on the source field

const orders = await Order.find({}).populate('source');

It returns fields with the ObjectId type, that is, it is populated, but does not return with the string type

[

    {
     _id: ObjectId('626101f10709bfd705ebaaff'),
     firstName: 'Peter',
     lastName: 'Parker',
     source: {_id: '625fa062cc69b9ccda60ff4b', name: 'Twitter'}
    },
    {
     _id: ObjectId('6229b108fb9da9e4ee29dcc4'),
     firstName: 'Oliver',
     lastName: 'Williams'
    },
    ...
]

How to make source fields with string type not deleted when request is answered

I want this result

[

    {
     _id: ObjectId('626101f10709bfd705ebaaff'),
     firstName: 'Peter',
     lastName: 'Parker',
     source: {_id: '625fa062cc69b9ccda60ff4b', name: 'Twitter'}
    },
    {
     _id: ObjectId('6229b108fb9da9e4ee29dcc4'),
     firstName: 'Oliver',
     lastName: 'Williams',
     source: 'Instagram'
    },
    ...
]

Please help, thanks in advance!!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source