I'm working on a REST API with Python (Flask + MongoDB) and during development I found that in no part of the code had I freed the resources of the database.
I've researched there but found nothing feasible about how to best approach this approach.
I do not know if MongoDB is self-manageable in this, or if I should programmatically manipulate it. Usually in Java or any other language, making use of drivers for SGDBs or ORMs, one has to worry about closing the connections with the bank when it is no longer being requested by the application.
For example, my class that provides the connection method looks like this:
from mongoengine import connect
from siava.app.aplicacao.utils.Configuracoes import Configuracoes
class Conexao(object):
"""
Mantem conexões com o banco de dados
"""
@classmethod
def conectar(self):
config = Configuracoes()
connect(
name=config.banco['banco'],
host=config.banco['host'],
port=config.banco['porta'],
username=config.banco['usuario'],
password=config.banco['senha'])
The mongoengine (which encapsulates the PyMongo ) until you have the disconnect () method but in the documentation you have nothing about using it. It may be for internal use and not part of the / api resource usage interface.
With that, the question remains, should I control the release of bank resources or is it managed in some way by MongoDB itself, or even by the ODM?