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

Allow passing dict to sort/create_index/hint

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Backlog
    • Unknown
    • Resolution: Unresolved
    • None
    • 4.6
    • None
    • None

    Description

      >>> 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+.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              shane.harvey@mongodb.com Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: