How can I join two collections from different databases in mongoDB?

I have two collections Post (belongs to posts database) and User (belongs to account database). My requirements to do join on these two collection. But I am unable to reproduce my requirements.

Hi Muhammad_umer_Farooq

By “joining” you mean running one single query over the different collections in the different databases? If yes I am afraid this is not possible directly across different databases. If the two collections are in the same database, you can use the aggregation operator $unionWith to include another collection in your current aggregation pipeline.
Only if you host your databases on Atlas you can add your databases to a Data Lake and then run queries across multiple clusters and databases. But if you are running an on-prem instance, this is not possible.

1 Like

Hello,
Is there any way to use connect two collections belonging to two different databases? The way we use referencing with"ref" to relate two collections in a database, can I relate two collections somehow belonging to two different databases?

thanks in advance : )