PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to close a mongodb python connection?

 April 20, 2022     connection, mongodb, pymongo, python     No comments   

Issue

I'm doing a python script that writes some data to a mongodb. I need to close the connection and free some resources, when finishing.

How is that done in Python?


Solution

Use close() method on your MongoClient instance:

client = pymongo.MongoClient()

# some code here

client.close()

close() is an alias for disconnect() method:

Disconnecting will close all underlying sockets in the connection pool. If this instance is used again it will be automatically re-opened.



Answered By - alecxe
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing