Database reference

This document supplements Django’s documentation on databases.

Persistent connections

Persistent connections avoid the overhead of reestablishing a connection to the database in each HTTP request. They’re normally controlled by the CONN_MAX_AGE parameter which defines the maximum lifetime of a connection. However, this parameter is unnecessary and has no effect with Django MongoDB Backend because Django’s API for connection-closing (django.db.connection.close()) has no effect. In other words, persistent connections are enabled by default.

Connection management

Django uses this backend to open a connection pool to the database when it first makes a database query. It keeps this pool open and reuses it in subsequent requests.

The underlying MongoClient takes care connection management, so the CONN_HEALTH_CHECKS setting is unnecessary and has no effect.

Django’s API for connection-closing (django.db.connection.close()) has no effect. Rather, if you need to close the connection pool, use django.db.connection.close_pool().