Query across collections in multiple databases in the same cluster

Hello!

For starters, I am new to MongoDB. I started using MongoDB for my capstone, as I needed to work with a client. The client requested that I use MongoDB for this project. He also is requesting a lot of specifics about the cluster, and one of them being that he wants to be able to query across multiple databases.

After doing some research, I see that I will most likely need to make use of the Data Lake feature. But, all of the documentation about this feature was for querying across multiple databases in different clusters.

So, my question is can I query across multiple databases in the same cluster using a data lake? Or is there a better route that I should take?

Thank you!

Hi @Thomas_Hanley and welcome to the MongoDB community forum!!

To query the data from different collection in different database, you can make use of db.getSiblingsDB() to access the other database. However, this command is a mongosh method and cannot be run in the Atlas Data Explorer UI.

If it is not a compulsory requirement, you can move the collection inside the same database and make use of $lookup.
You can visit the $lookup documentation for more information.

Just for further clarification, Atlas Data Lake and Atlas Data Federation (previously called Atlas Data Lake) are different. Would you be able to confirm if Atlas Data Lake is the feature you were looking into? In saying so:

The Data Lake are storage repositories to store the data in its original format.

The MongoDB Atlas Data Federation allows you to query among different MongoDB systems, including Clusters, Databases, and even AWS S3 buckets.
You can read the blog post on Data Lake federation for more information.

Let us know if you have further questions.

Regards
Aasawari

1 Like