title: pouchDB retrieve allDocs original query
body: <p>I am attempting to load a local PouchDB with results from a website. Once the results are loaded locally, I don't want to bother with downloading them again. </p>
  
  <p>To avoid this, I get a list of files that exist, and then test to see if I've loaded it in the past before fetching it.</p>
  
  <pre><code>function DownloadFile($fname){
          $query = {
              include_docs: false,
              attachments: false,
              startkey: ['run',$fname].join(','),
              endkey: ['run',$fname,'\uffff'].join(',')
          };
          db.allDocs($query).then(function (result) {
              if ( result.rows.length !== 0 ) return;
              $url = './runDb/' + $fname + '/results.xml';
              $.ajax({
                  url: $url,
                  type: "GET",
                  dataType: "xml",
                  contentType: "text/xml",
                  async: true,
                  success: function (results,status,xhr) {
                      app.ParseResults($fname,results)
                  }
              });
          }).catch(function (err) {
              console.log(err);
          });
  }
  </code></pre>
  
  <p>The problem I am having is that by the time <code>DownloadFile</code> get's called 100 times and the <code>allDocs</code> query finally returns something, I no longer know what the original query that returned no results.</p>
  
  <p>Is there a way in PouchDb to determine the query parameters that were used to produce a given result set? </p>
  
  <p><em>EDIT</em>: While I really like the accepted answer, it appears this was a dumb question. Experimentation (in the browser) indicates that <code>$query</code> and <code>$fname</code> will contain the correctly scoped value for the particular call that initiated <code>allDocs</code> call.</p>
  
  <p>In other words, I don't really need to do anything, it just works. Obviously, this is highly dependant on the JS implementation, therefore the accepted answer is better because it is explicit about what is desired.</p>