0
0
MongoDBquery~30 mins

Atlas data federation concept in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Atlas Data Federation with MongoDB
📖 Scenario: You work for a company that stores customer data in multiple MongoDB collections across different clusters. You want to create a unified view of all customers using Atlas Data Federation, so you can query all data as if it were in one place.
🎯 Goal: Build a simple Atlas Data Federation query that combines customer data from two collections into one result set.
📋 What You'll Learn
Create two collections named customers_us and customers_eu with sample customer documents
Create a data federation virtual database that includes both collections
Write a query to find all customers from both collections
Filter customers with age greater than 30
💡 Why This Matters
🌍 Real World
Companies often store data in multiple databases or clusters. Atlas Data Federation lets you query all data together without moving it.
💼 Career
Understanding data federation helps in roles like data engineering and database administration where combining data from multiple sources is common.
Progress0 / 4 steps
1
Create two collections with sample customer data
Create two collections named customers_us and customers_eu with these exact documents: {"name": "Alice", "age": 28} and {"name": "Bob", "age": 35} in customers_us, and {"name": "Clara", "age": 40} and {"name": "David", "age": 25} in customers_eu.
MongoDB
Need a hint?

Use insertMany to add multiple documents to each collection.

2
Configure the Atlas Data Federation virtual database
Create a data federation virtual database named customerFederation that includes the collections customers_us and customers_eu from your clusters.
MongoDB
Need a hint?

Use the Atlas UI or API to create a data federation virtual database named customerFederation that includes both collections.

3
Write a query to find all customers from both collections
Write a MongoDB query on the customerFederation virtual database to find all documents from the combined collections customers_us and customers_eu.
MongoDB
Need a hint?

Use $unionWith to combine documents from customers_us and customers_eu.

4
Filter customers with age greater than 30
Extend the query on customerFederation to only return customers whose age is greater than 30.
MongoDB
Need a hint?

Add a $match stage after $unionWith to filter by age.