Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:22:06+00:00 2026-06-09T20:22:06+00:00

I am fairly new to databases and have just figured out how to use

  • 0

I am fairly new to databases and have just figured out how to use MongoDB in python2.7 on Ubuntu 12.04. An application I’m writing uses multiple python modules (imported into a main module) that connect to the database. Basically, each module starts by opening a connection to the DB, a connection which is then used for various operations.

However, when the program exits, the main module is the only one that ‘knows’ about the exiting, and closes its connection to MongoDB. The other modules do not know this and have no chance of closing their connections. Since I have little experience with databases, I wonder if there are any problems leaving connections open when exiting.

Should I:

  • Leave it like this?

  • Instead open the connection before and close it after each operation?

  • Change my application structure completely?

  • Solve this in a different way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:22:08+00:00Added an answer on June 9, 2026 at 8:22 pm

    You can use one pymongo connection across different modules. You can open it in a separate module and import it to other modules on demand. After program finished working, you are able to close it. This will be the best option.

    About other questions:

    1. You can leave like this (all connections will be closed when script finishes execution), but leaving something unclosed is a bad form.
    2. You can open/close connection for each operation (but establishing connection is a time-expensive operation.
    3. That what I’d advice you (see this answer’s first paragraph)
    4. I think this point can be merged with 3.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im fairly new to databases in vb.net and i have just learned how to
I'm fairly new to working with relational databases, but have read a few books
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
So I am fairly new to android programming. I have a database and I
Fairly new to programming. I just can't wrap my head around how to get
I am new to fairly new to AS3 and I have found myself needing
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I've got a really simple problem but I just can't sort it, fairly new
I'm fairly new to programming and have been focussing a great deal on Java
I'm fairly new to facebook development, but have experience with PHP and JavaScript. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.