Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

How to close connections? #248

Open
sushuai opened this issue Dec 31, 2015 · 1 comment
Open

How to close connections? #248

sushuai opened this issue Dec 31, 2015 · 1 comment

Comments

@sushuai
Copy link

sushuai commented Dec 31, 2015

I can not find the method closed conntions,when I run program, the conntions growing fast until mongodb conntions full and then I can not connect to mongodb, how can I close connections?

@ferstar
Copy link

ferstar commented Mar 1, 2016

@sushuai It's simple to close connections opened by MongoKit. Here are my solution:

# create a connection
connection = Connection()
# do something
...
# close the connection
connection.close()

And even more, if you use MongoKit in a Flask-RESTful project, it's also very simple to close connections opened by each API request:

from flask import Flask
from flask_restful import Api


app = Flask(__name__)
api = Api(app)

@app.teardown_request
def teardown_request(exception):  # close db connection after each api request
    connection.close()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants