title: How to return a large set of records from cloudant by using db.search?
body: <p>db.find works fine but it's very slow. So I'm trying to use db.search with search index but it limits to 200 records. So then I'm calling same search to go thorough all bookmarks by using nested promise that runs in out of memory. Is anything wrong with the code below?</p>
  
  <pre><code>let qOptions;
  qOptions = {'include_docs': true, limit: 200}
  qOptions.q = "name: 'BEN'";
  
  let allDocuments = [];
  this.getAllDocuments(qOptions, allDocuments, 'app', 'myIndex')
  .catch(err =&gt; {
    ....
  })
  .then((result) =&gt; {
    ....
  });
  </code></pre>
  
  <p>and then the recurring promise:</p>
  
  <pre><code>getAllDocuments(queryOpqOptionstions, allDocuments, designName, indexName) {
    const promise = new Promise((resolve, reject) =&gt; {
      dbConnection.search(designName, indexName, qOptions, (err, result) =&gt; {
        if (!err) {
          if (result.rows.length === 0) {
            resolve(allDocuments)
          } else {
            qOptions.bookmark = result.bookmark;
            result.rows.forEach((result) =&gt; {
              allDocuments.push(result)
            })
  
            this.getAllDocuments(qOptions, allDocuments, designName, indexName).then((docs) =&gt; {
              resolve(docs);
            }).catch((error) =&gt; {
              logger.error({err: error});
              reject(error);
            })
          }
        } else {
          logger.error({err: err});
          reject(err);
        }
      })
    })
  
    return promise;
  }
  </code></pre>