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

  • Home
  • SEARCH
  • 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 9130239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:55:35+00:00 2026-06-17T07:55:35+00:00

So I have a few machines on the network running MongoDB: I can easily

  • 0

So I have a few machines on the network running MongoDB:

  • I can easily write code to connect to one from my PC and return a result set, e.g.:
from pymongo import Connection
c = Connection("10.130.10.12")
some_data = c.MyData.MyCollection.find_one()
  • If I have, say 100 servers to connect to, and want to put this in a loop, that’s easy too:
all_data = []
for server in my_list_of_servers:
    c = Connection(server)
    all_data.append(c.MyData.MyCollection.find_one())
  • However this does it one-by-one and could be quite slow.
  • How can I send out all the requests at once? I’m super unfamiliar with threading (is that what I should even be looking into?)
  • 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-17T07:55:37+00:00Added an answer on June 17, 2026 at 7:55 am
    from multiprocessing import Pool
    
    def connectAndCollect(server):
        c = Connection(server)
        return c.MyData.MyCollection.find_one()
    
    pool = Pool(processes=10)
    res = pool.map(connectAndCollect,servers)
    map(lambda x: all_data.append(x),res)
    pool.close()
    

    The multiprocessing library is designed for this sort of task. The final map call can be replaced by a for loop if you like.

    A description of using the multiprocessing module for Map/Reduce tasks in general is described here:
    http://mikecvet.wordpress.com/2010/07/02/parallel-mapreduce-in-python/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few asp.net web applications running on a dedicated server.. For one
I have a few repos on a Windows network drive and I can check
As I have to setup quite a few Windows Server machines, I decided to
I've tried this on a few machines on different networks, all running ruby 1.8.7
I have a book called Network Programming in .NET which has the following code
I have a snippet of code which checks if the network is available, and
We have a web application deployed on quite a few AWS machines, all served
I have a few macros that are working on coworkers machines however when I
I have generated a few network graphs in igraph. I like to use tkplot,
I have to kill frequently few processes(services) on my developer machine to release memory

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.