title: MongoDB sort used more than the maximum RAM, but is using an index?
body: <p>I'm debugging a site search feature with paginated results that is failing after an arbitrary number of pages.</p>
  
  <pre><code>search: Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.
  </code></pre>
  
  <p>However, I'm confident that it is using an index:</p>
  
  <pre><code>   winningPlan:
      { stage: 'PROJECTION',
        transformBy:
         { score: { '$meta': 'textScore' },
           shootId: 1,
           title: 1,
           publishDate: 1,
           'media.images.indexImage': 1,
           'media.images.adImage': 1,
           'media.images.galleryImages': 1,
           'media.images.portrait': 1,
           'media.promos.images.410': 1,
           'media.full.full.length': 1,
           contentProducer: 1,
           performers: 1,
           site: 1 },
        inputStage:
         { stage: 'TEXT',
           indexPrefix: {},
           indexName: 'textSearchIndex',
           parsedTextQuery:
            { terms: [ 'milk' ],
              negatedTerms: [],
              phrases: [],
              negatedPhrases: [] },
           textIndexVersion: 3,
           inputStage:
            { stage: 'TEXT_MATCH',
              inputStage:
               { stage: 'TEXT_OR',
                 filter:
                  { '$and':
                     [ { 'status.publishStatus': { '$eq': 'PUBLISHED' } },
                       { publishDate: { '$lte': 2017-03-17T21:30:29.254Z } } ] },
                 inputStage:
                  { stage: 'IXSCAN',
                    keyPattern:
                     { _fts: 'text',
                       _ftsx: 1,
                       'status.publishStatus': 1,
                       publishDate: -1 },
                    indexName: 'textSearchIndex',
                    isMultiKey: true,
                    isUnique: false,
                    isSparse: false,
                    isPartial: false,
                    indexVersion: 2,
                    direction: 'backward',
                    indexBounds: {} } } } } },
     rejectedPlans: [] },
  </code></pre>
  
  <p>The collection is ~1gb, 35k objects, average size 28.3 KiB.</p>
  
  <p>The index, which is 22.8 MiB:</p>
  
  <pre><code>{ 
      "description" : "text", 
      "performers.performerName" : "text", 
      "site.shortName" : "text", 
      "summary" : "text", 
      "title" : "text", 
      "status.publishStatus" : 1, 
      "publishDate" : -1
  }
  </code></pre>
  
  <p>The query:</p>
  
  <pre><code>{
    'status.publishStatus': 'PUBLISHED',
    'publishDate': {
      '$lte': new Date("Fri, 17 Mar 2017 21:30:29 GMT")
    },
    '$text': {
        '$search': 'milk'
    }
  }
  </code></pre>
  
  <p>The sort:</p>
  
  <pre><code>{
    score: {
      $meta: 'textScore'
    },
    publishDate: -1
  }
  </code></pre>
  
  <p>Practically, it's doing a find, sort, skip, limit, lean, select and finally exec.</p>
  
  <p>Is it actually indexed? If it's not, what should I do differently?</p>
  
  <p>If it is indexed, should I be increasing the internalQueryExecMaxBlockingSortBytes ?</p>