Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-927

Document the non-static nature of MongoClient.nodes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial - P5
    • Resolution: Fixed
    • 3.0, 3.0.1
    • 3.0.2
    • None
    • None
    • 3.0.2-1-dce3f36

    Description

      I'm passing around a MongoClient and sometimes need to know what I'm connected to (previously we used host, port).

      It looks like client.nodes is empty for sometime after Client creation:

      In [32]: for i in xrange(1000):
          c = pymongo.MongoClient('cn14-ib:27119')
          time.sleep(0.00001)
          assert c.nodes, i
         ....:     
      ---------------------------------------------------------------------------
      AssertionError                            Traceback (most recent call last)
      <ipython-input-32-993619bacd76> in <module>()
            2     c = pymongo.MongoClient('cn14-ib:27119')
            3     time.sleep(0.00001)
      ----> 4     assert c.nodes, i
            5 
       
      AssertionError: 12
      

      The docs say:
      http://api.mongodb.org/python/current/api/pymongo/mongo_client.html?highlight=mongoclient#pymongo.mongo_client.MongoClient.nodes

      nodes
      List of all connected servers.
      Nodes are either specified when this instance was created, or discovered through the replica set discovery mechanism.

      In this case nodes is empty, so is neither what was passed into the MongoClient, nor discovered...

      If you put a server_info() in there, then nodes is reliable. Is there a better way to get the original connection string?

      Attachments

        Activity

          People

            bernie@mongodb.com Bernie Hackett
            jblackburn James Blackburn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: