3
I am working on a REST API with Python (Flask + Mongodb) and during development I checked that, nowhere in the code, had I released the resources from the database.
I have researched around but found nothing feasible about the best way to work this approach.
I don’t know if Mongodb is self-manageable about it, 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 connections with the database when it is no longer being requested by the application.
For example, my class that provides the connection method is 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 (that encapsulates the Pymongo) even has the Disconnect() method but in the documentation has nothing about the use of it. It may be in-house and not part of the resource usage interface/api.
With this, the doubt remains, I must control the release of bank resources or somehow this is managed by Mongodb itself, or even by the ODM?
I understand, vlw by the tips. I will try to give a studied on this issue on the treatment of connections on the Flask side. I use mongoengine as ODM for the document abstraction and persistence layer, Flask is using only as FW REST because in Hug (http://www.hug.rest/) I had some problems with POST capture.
– Robson