M220JS: Chapter 4: Resiliency

MongoDB for JavaScript Developers(Chapter 4 of 4)

Introduction to Chapter 4

Application Resilience & Robustness

Connection Pooling

Connection pooling is all about reusing database connections. Because creating a database connection is time-consuming, it will be better to create several connections ahead.

In MongoDB, 100 connctions will be created by default.


  • Connection pools allow for reuse of connections
  • Subsequent requests appear faster to the client
  • Default size of 100(seems large)

New operations can be serviced with pre-existing connections, so a new connection doesn’t have to be created each time. A large influx of operations can be handled more quickly with a pool of existing connections.

Robust Client Configuration

  • Always using connection pooling.
  • Always specify a wtimeout with majority writes.
  • Always configure for and handle serverSelectionTimeout errors.

When should you set a wtimeout?
When our application is using a Write Concern more durable than w: 1.

Error Handling

Principle of Least Privilege