MongoDB Assignment- 5
Basic Questions
- Enable sharding on shopDB, insert 5M docs into orders, and run sh.status() to observe sharding in action.
- Set up replication and sharding in a test environment, then run rs.status() vs sh.status() to observe their behavior differences.
- Create a collection users and enable a shard key on the userId field.
- Scale MongoDB in Docker twice: once by adding CPU/memory (vertical) and once by adding shards (horizontal), then compare performance using inserts
- Enable sharding on a database named ecommerce.
- Create a text index on the description field of the products collection.
- Perform a full-text search query for “laptop” in the products collection.
- Insert a document into locations with name, latitude, and longitude.
- Create a 2dsphere geospatial index on the locations collection.
- Write a query to find all places within 5km of a given point.
- Insert 3 sample documents into a time-series collection named sensorData.
- Create a time-series collection in MongoDB with timeField: “timestamp”.
- Show how to query documents in sensorData for the last 1 hour.
- In MongoDB Atlas, create a cluster named TrainingCluster.
- Demonstrate how to configure IP whitelisting in Atlas.
- Enable encryption at rest in MongoDB Atlas.
- Create an alert in Atlas when CPU usage exceeds 80%.
- Enable TLS/SSL connections for MongoDB and connect with –tls parameter to verify secure communication.
- View cluster metrics and performance graphs in Atlas dashboard.
- Trigger a manual backup in Atlas from UI/API, then configure automated backup policy and observe differences in restore options.
Intermediate Questions
- Configure a 3-shard cluster with one config server and one mongos router.
- Create a students collection, shard it on two different keys (rollNo vs class), and measure query performance for each.
- Demonstrate how to reshard a collection in MongoDB.
- Insert 10K docs into orders, enable sharding, then run db.orders.getShardDistribution() to view how data is distributed.
- Create two sharded collections: one with range‑based shard key and one with hashed shard key, then compare query times for lookups.
- Write a full-text search query to find documents with “apple” but exclude “juice”.
- Use the $text operator with a relevance score to sort search results.
- Create a multilingual full-text search index supporting English and Hindi.
- Write a query using $geoWithin to find restaurants in a defined polygon (city boundary).
- Use $near query to list the nearest 5 hospitals from a given location.
- Create a compound index combining timestamp and sensorId in time-series data.
- Run a query to calculate the average temperature from time-series sensorData.
- In Atlas, upgrade a cluster tier from M10 to M20 and log query performance before vs after scaling.
- Configure VPC Peering in Atlas with a cloud app, then ping the DB from your app to test connectivity.
- Write a script to automatically back up salesDB every 24 hours using Atlas automated backups.
- Stop the primary node in Atlas, then run rs.status() to capture the failover event and time taken for new primary election.
- Create a role-based access control in Atlas allowing only read access for analytics users.
- Configure Atlas network rules to restrict connections only to India IP range and attempt a connection from outside India to verify denial.
- Monitor query performance using Atlas Performance Advisor.
- Create a custom alert in Atlas for slow query execution.
Advanced Questions
- Create a sharded orders collection in a cluster handling simulated 1M orders/day, test possible shard keys (orderId vs customerId) and measure query balance.
- Move a chunk manually using moveChunk between two shards and check performance logs before and after.
- Generate heavy writes into a sharded collection and run sh.status() to observe how the balancer redistributes chunks automatically.
- Implement text search + geospatial query together (e.g., “Find cafés mentioning ‘coffee’ within 2 km”).
- Build two multilingual text indexes (English & Hindi) and run searches to demonstrate language‑specific stemming differences.
- Ingest live IoT sensor data into a time‑series collection, then create an aggregation query to detect anomalies (e.g., temperature > 100°C).
- Partition time‑series data into hot (recent) and cold (archived) collections and query both to illustrate tiered storage.
- Deploy Atlas Global Clusters in Asia + US, then run queries with readPreference: nearest from both regions to measure latency.
- Enable both “Encryption at Rest” and “TLS in Transit” in Atlas, then test connectivity with a secure client certificate.
- Configure an Atlas alert + auto‑scaling rule that upgrades cluster tier when memory hits 75% and verify it with workload simulation.