I am using PyMongo, and I have some questions about connection and cursor.
A. Do I have to close a cursor? I want to know because I really want to do something like this.
for s in collection.find():
print(s)
B. Do I have to close a MongoClient manually? Will it affect the connection polling feature of PyMongo?
from pymongo import MongoClient
url = 'mongodb://localhost:27017'
client = MongoClient(url)
db = client['test']
collection = db['students']
# QUERY
cursor = collection.find()
for s in cursor:
print(s)
cursor.close() # Is this required?
client.close() # Is this required?
I am not sure if there are any differences.