title: What is the best way for pagination on mongodb using java
body: <p>I am trying to create a simple pagination in mongodb by below code.</p>
  
  <pre><code>collection.find().skip(n).limit(n);
  </code></pre>
  
  <p>but doesn't it looks like there will be a performance issue if we see that in java terms first find will return all the records consider i have 2 million records, then it will pass it to skip method then it will be passed to limit method. it means every time this query will be fetching all the db records or mongodb drivers work differently, what i missed?</p>