I'm curious if this is right working.
In case of using MySQL, both connecting and closing are done per one request.
1st request: connect, close
2nd request: connect, close
3rd request: connect, close
4th request: connect, close
5th request: connect, close
every requests bring both connect and close
This is how I manage MySQL connection and think many of other developer do like this.
BUT..
In case of using mongodb with PyMongo module, it works not like above.
1st request: connect
2nd request: connect
3rd request: (use connection of 1st or 2nd) <= Do not connect but use previous connection
4th request: (use connection of 1st or 2nd) <= same
5th request: (use connection of 1st or 2nd) <= same
Does this keep the connection in app.config and use on after request?
I feel How it works is very difficult from managing connection of MySQL.
Is this normal working?
Doesn't it need to close the connection after using?
from flask import Flaskfrom flask_pymongo import PyMongoapp = Flask(__name__)app.config['MONGO_HOST'] = '127.0.0.1'app.config['MONGO_PORT'] = 27017app.config['MONGO_DBNAME'] = 'test'mongo = PyMongo(app, config_prefix='MONGO')@app.route('/')def test(): mongo.db.user.insert({'name':'test'}) return 'test'if __name__ == '__main__': app.run()
Thank you for read.