MongoDB can be connected from Node by calling the connect() method of MongoClient class.
javascript
Scenario Questions
0-2 years experience
1We have a simple Node.js script that needs to read a collection from a local MongoDB. How would you establish the connection?
2If you forget to include the database name in the connection string, what will happen when you run a query?
3During startup the app crashes with a connection error. What steps do you take to handle that gracefully?
2-5 years experience
1Your new feature writes logs to MongoDB, but after deployment you see intermittent MongoNetworkError timeouts. How would you debug and resolve this?
2You need to support separate dev and prod MongoDB credentials without hard‑coding them. How would you structure the connection code?
3Explain why you might enable the unified topology option and what impact it has on connection handling.
5-8 years experience
1At high load the service opens many connections and memory usage spikes. How would you redesign the connection handling to be more efficient?
2Describe how you would implement a graceful shutdown that ensures all pending MongoDB operations finish before the process exits.
3What configuration would you choose for connection pooling and retry logic for a microservice handling thousands of requests per second?
8+ years experience
1Our monolith is being split into multiple services, each needing MongoDB access. What architectural pattern would you use for managing connections across services?
2How would you design a shared MongoDB connection library that satisfies security, observability, and versioning requirements across several teams?
3If we need multi‑region read/write with eventual consistency, how does that affect your connection strategy and driver options?
Follow-up Questions
Can you sketch the minimal code you would write?
What would you monitor to know the connection is healthy?
How would you test connection failures in CI?
Sharethis question
Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.