title: Pymongo throws "OperationFailure: The key is too long"
body: <p>After updating MongoDB from version 3.4.17 to 4.0.12 from time to time, when executing <code>mongo.conn.COLLECTION_NAME.find({'email': ['1'] * 2000})</code>, while email is a string value, the following error is thrown:</p>
  
  <pre><code>  File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 787, in count
      cmd, self.__collation, session=self.__session)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 1600, in _count
      _cmd, self._read_preference_for(session), session)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 1465, in _retryable_read
      return func(session, server, sock_info, slave_ok)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 1594, in _cmd
      session=session)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 250, in _command
      user_fields=user_fields)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 613, in command
      user_fields=user_fields)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/network.py", line 167, in command
      parse_write_concern_error=parse_write_concern_error)
    File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 159, in _check_command_response
      raise OperationFailure(msg % errmsg, code, response)
  OperationFailure: The key is too long
  </code></pre>
  
  <p>The returned error code is: 17280</p>
  
  <p><strong>Python</strong>: 2.7.16<br>
  <strong>Pymongo</strong>: 3.9.0 </p>
  
  <p>The query execution plan is:</p>
  
  <pre><code>{'executionStats': {'allPlansExecution': [],
    'executionStages': {'advanced': 0,
     'alreadyHasObj': 0,
     'docsExamined': 0,
     'executionTimeMillisEstimate': 0,
     'filter': {'email': {'$eq': ['1',...,'1']}},
     'inputStage': {'advanced': 0,
      'direction': 'forward',
      'dupsDropped': 0,
      'dupsTested': 0,
      'executionTimeMillisEstimate': 0,
      'indexBounds': {'email': ['["1", "1"]', '[[ "1", ... , "1" ]]']},
      'indexName': 'email_1',
      'indexVersion': 2,
      'invalidates': 0,
      'isEOF': 1,
      'isMultiKey': False,
      'isPartial': False,
      'isSparse': False,
      'isUnique': False,
      'keyPattern': {'email': 1},
      'keysExamined': 1,
      'multiKeyPaths': {'email': []},
      'nReturned': 0,
      'needTime': 1,
      'needYield': 0,
      'restoreState': 0,
      'saveState': 0,
      'seeks': 2,
      'seenInvalidated': 0,
      'stage': 'IXSCAN',
      'works': 2},
     'invalidates': 0,
     'isEOF': 1,
     'nReturned': 0,
     'needTime': 1,
     'needYield': 0,
     'restoreState': 0,
     'saveState': 0,
     'stage': 'FETCH',
     'works': 2},
    'executionSuccess': True,
    'executionTimeMillis': 0,
    'nReturned': 0,
    'totalDocsExamined': 0,
    'totalKeysExamined': 1},
   'ok': 1.0,
   'queryPlanner': {'indexFilterSet': False,
    'namespace': 'DATABASE_NAME.COLLECTION_NAME',
    'parsedQuery': {'email': {'$eq': ['1', ... , '1']}},
    'plannerVersion': 1,
    'rejectedPlans': [],
    'winningPlan': {'filter': {'email': {'$eq': ['1', ... ,  '1']}},
    'inputStage': {'direction': 'forward',
      'indexBounds': {'email': ['["1", "1"]', '[[ "1", ... ,"1" ]]']},
          'indexName': 'email_1',
      'indexVersion': 2,
      'isMultiKey': False,
      'isPartial': False,
      'isSparse': False,
      'isUnique': False,
      'keyPattern': {'email': 1},
      'multiKeyPaths': {'email': []},
      'stage': 'IXSCAN'},
     'stage': 'FETCH'}},
   'serverInfo': {'gitVersion': '5776e3cbf9e7afe86e6b29e22520ffb6766e95d4',
    'host': '*****',
    'port': 27037,
    'version': '4.0.12'}}
  </code></pre>
  
  <p>The error probably caused by a tremendous value (a long list) comparison, but I didn't find any documentation about it.  </p>
  
  <p>Is it a restriction that was added in version 4.0?</p>