title: What is a Cursor in MongoDB?
body: <p>We are troubled by eventually occurring <code>cursor not found exceptions</code> for some Morphia Queries <a href="http://mongodb.github.io/morphia/1.0/guides/querying/" rel="noreferrer"><code>asList</code></a> and I've found a <a href="https://stackoverflow.com/a/25201116/2092322">hint on SO</a>, that this might be quite memory consumptive.</p>
  
  <p>Now I'd like to know a bit more about the background: can sombody explain (in English), what a Cursor (in MongoDB) actually is? Why can it kept open or be not found?</p>
  
  <hr>
  
  <p>The documentation <a href="https://docs.mongodb.org/manual/reference/glossary/#term-cursor" rel="noreferrer">defines</a> a cursor as:</p>
  
  <blockquote>
    <p>A pointer to the result set of a query. Clients can iterate through a cursor to retrieve results. By default, cursors timeout after 10 minutes of inactivity</p>
  </blockquote>
  
  <p>But this is not very telling. Maybe it could be helpful to define a <code>batch</code> for query results, because the <a href="https://docs.mongodb.org/manual/core/cursors/#read-operations-cursors" rel="noreferrer">documentation also states</a>:</p>
  
  <blockquote>
    <p>The MongoDB server returns the query results in batches. Batch size will not exceed the maximum BSON document size. For most queries, the first batch returns 101 documents or just enough documents to exceed 1 megabyte. Subsequent batch size is 4 megabytes. [...] For queries that include a sort operation without an index, the server must load all the documents in memory to perform the sort before returning any results.</p>
  </blockquote>
  
  <p>Note: in our queries in question we don't use sort statements at all, but also no <code>limit</code> and <code>offset</code>.</p>