Aggregate multiple databases (one DB is placed locally on PC, second - on host in net)

Cans anybody to provide the ‘real world’ simple example of using aggregation function and join 2 collections from 2 DBs (placed as mention in this title), something like here: . Generally, Is it possible?

Thanks in advance.

Hi @Andrei

I don’t think MongoDB can join two databases where one is on-prem, but I believe you can join multiple MongoDB Atlas based databases in a single query using Atlas Data Federation. Using Data Federation you can also join Atlas Data Lake and data in AWS S3 buckets.

Best regards


Nothing stops you from implementing your own federation.

You just connect your application to the 2 servers, reading data from both and storing the result where ever you wish.

You can even do that by simply doing 2 mongodump, one from each servers. The mongorestore to 2 different databases to the target mongod, then use aggregation with $merge in the order you want.

1 Like

Salut Steeve! Yes, we have the middleware in our project and I’m able to call the api routes to get data from the desired collections. Actually I need to compare metadata in related collections and update data in the local collection by the user call by the running a script (Node + js). This script (Node + js) does not work properly and we do not use refs in our mongoose schema . I’d like ro rewrite it with using aggregation func. Could you, pls, write for me the short example of code how to create/merge those collections to temporary/ virtual DB, then put make to aggregation func.?

Thanks Kevin for your answer! Can you get me the simple example how can I make it with using JavaScript code? Or link for tutorial?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.