'How to join in mongoDB by passing from collection name dynamic

I want to get data by using join in mongoDB but I want to get data from collection which is different for each record as like below example

=> Collection A : it has three fields in it ["_id", "name", "relatedTo"]

RelatedTo has collection name in which we have to join and get data from that collection. can some one help me how can I do.

Thank you.



Sources

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

Source: Stack Overflow

Solution Source