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

Allow passing dict to sort/create_index/hint

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.6
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      >>> client.t.t.find(hint={'x': 1})
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 1381, in find
          return Cursor(self, *args, **kwargs)
        File "/Users/shane/git/mongo-python-driver/pymongo/cursor.py", line 220, in __init__
          self.__set_hint(hint)
        File "/Users/shane/git/mongo-python-driver/pymongo/cursor.py", line 860, in __set_hint
          self.__hint = helpers._index_document(index)
        File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 86, in _index_document
          raise TypeError("passing a dict to sort/create_index/hint is not "
      TypeError: passing a dict to sort/create_index/hint is not allowed - use a list of tuples instead. did you mean [('x', 1)]?
      

      Now that we've dropped support for Python <=3.5 (PYTHON-2386) we should allow passing dict to sort/create_index/hint. Dicts are always ordered by insertion order in 3.6+.

            Assignee:
            noah.stapp@mongodb.com Noah Stapp
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: