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

pymongo cannot access collection named 'connection'

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 2.5
    • Affects Version/s: 2.4.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      python 2.6 and 2.7, pymongo 2.4.2, mongod 2.2, osx and ubuntu

      1 : import pymongo
      2 : m=pymongo.Connection().test
      3 : m.comment.count()
      4 : m.connection.count()

      test db has comment and connection collections
      #3 succeeds, #4 crashes with
      /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/database.pyc in _call_(self, *args, **kwargs)
      798 "call the '%s' method on a '%s' object it is "
      799 "failing because no such method exists." % (
      --> 800 self._name, self.connection.class.name_))
      801
      802

      TypeError: 'Database' object is not callable. If you meant to call the 'count' method on a 'Connection' object it is failing because no such method exists.

      Cause seems to be that 'connection' is a method in pymongo and conflicts with the valid 'connection' collection name.

      Workaround is use bracket notation:
      In [10]: m["connection"].count()
      Out[10]: 22

      A corner case with a workaround. Still, its a valid collection name and hopefully can be easily fixed.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            jwright john wright
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: